Kamis, 08 Oktober 2015

Filter by and operator in AngularJs

In this post I will show you how to use && operator in AngularJs.
Example I have a students list as below:

 $scope.students = [  
{ name: 'Hai', age: 25, gender: 'boy' },
{ name: 'Hai', age: 30, gender: 'girl' },
{ name: 'Ho', age: 25, gender: 'boy' },
{ name: 'Hoan', age: 40, gender: 'girl' },
{ name: 'Hieu', age: 25, gender: 'boy' }
];

I want to filter students via gender to be boy and filter by name of them.

The first I create a function named "filterbyboy" as following:

 $scope.filterbyboy = function (genderstr) {  
if ((typeof $scope.search === 'undefined')||($scope.search === ''))
return (genderstr = "")
else
return (genderstr = "boy");
};

Explaination: if not filter name then display all students else filter by input name and gender as 'boy'

Here is full HTMLcode

Read more »

Bagikan

Jangan lewatkan

Filter by and operator in AngularJs
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.