TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
nav a
NA
29
2.5k
Angular4: need filter on start data and end date select
May 19 2018 12:43 PM
need to write code for two select box to filter on click.
//please correct the pipe
import { Pipe, PipeTransform } from
'@angular/core'
;
import { DatePipe } from
'@angular/common'
;
@Pipe({
name:
'filterMonthYear'
})
export
class
FilterMonthYearPipe implements PipeTransform {
transform(value:any, startmonth:
string
, endmonth :
string
): any{
if
(value.length === 0){
return
value;
}
const
resultArray = [];
console.log(startmonth);
console.log(endmonth);
var from_date = Date.parse(startmonth);
var to_date = Date.parse(endmonth);
for
(
const
item of value)
{
if
(item.startmonth > from_date && item.endmonth < to_date) {
resultArray.push(item);
}
};
return
resultArray;
}
}
html
<
label
>
Start Month
</
label
>
<
select
class
=
"form-control"
name
=
"selectedstart"
[(ngModel)]="selectedstartmonth"
>
<
option
>
Choose..
</
option
>
<
option
*
ngFor
=
"let table of TableData"
>
{{table.startmonth}}
</
option
>
</
select
>
<
p
>
{{selectedstart}}
</
p
>
</
div
>
<
div
class
=
"col-xs-6 col-sm-6 col-md-6"
>
<
label
>
End Month
</
label
>
<
select
class
=
"form-control"
name
=
"selectedend"
[(ngModel)]="selectedendmonth"
>
<
option
>
Choose..
</
option
>
<
option
*
ngFor
=
"let table of TableData"
>
{{table.endmonth}}
</
option
>
</
select
>
<
button
class
=
"btn btn-primary"
type
=
"submit"
(click)="getFilteredDate(startmonth.value, endmonth.value)"
>
Submit
</
button
>
<
tr
*
ngFor
=
"let table of TableData | filterMonthYear:selectedstartmonth:selectedendmonth"
>
<
td
class
=
'td-group1'
>
{{table.description}}
</
td
>
<
td
>
{{table.money}}
</
td
>
<
td
>
{{table.test}}
</
td
>
<
td
>
{{table.bbb}}
</
td
>
</
tr
>
component.ts
getFilteredDate(startmonth, endmonth){
//what can be the logic
}
Reply
Answers (
8
)
$http.jsonp error : Failed to execute 'removeChild' on 'Node
why we should use Angular ?