Hello I want to display a list of users data but I have put a condition on that if user data is greater than 0 then display otherwise not with help of length property in *ngIf
, so my issue when I use this it gets error like Cannot read property 'length' of undefined
,So please anyone help me.
I also show same question on angular2 version but didn't help much.Here is my view.
<div *ngIf="(studentListData | filter).length == 0">
<h3>Sorry ..!data not found</h3>
</div>
<div *ngIf="(studentListData | filter | filter ).length > 0>
<tr *ngFor="let student of studentListData | filtter; index as i;">
// ** here is my td *//
</tr>
</div>
In my component
export class studentAllComponet implements OnInit {
studentListData:any;
getStudentList(){
let studentList = this.studentService.getAllStudents();
this.success(studentList)
}
success(data){
this.studentListData = data;
for (var i = 0; i < this.studentListData.length; i++) {
this.studentListData[i].name = this.studentListData[i].first_name +' '+ this.studentListData[i].last_name;
}
}
}
In my filter
@Pipe({ name: 'filtter' })
export class FiltterPipe implements PipeTransform{
transform(value: any, args?: any): any {
if (args != undefined && args != null && args != '') {
return value.filter(data => (data.name.toLowerCase()).indexOf(args.toLowerCase()) > -1);
}
return value;
}
}
Thanks in advance..!