|
Answer» Example of using filter in an Angular controller Below is the example of using filter in an Angular controller and synatx is GIVEN below:- $scope.ListOfBooks = [ { BookID: 1, Name: "ASP.NET", Price: "600", Level: "I" }, { BookID: 2, Name: "C#", Price: "1000", Level: "I" }, { BookID: 3, Name: "VB.NET", Price: "700", Level: "III" }, { BookID: 4, Name: "Java", Price: "800", Level: "III" }, { BookID: 5, Name: "Perl", Price: "1000", Level: "II" }, { BookID: 6, Name: "Cobol", Price: "500", Level: "I" } ];
$scope.ListOfLevel = $scope.ListOfBooks.filter(function (Book) { RETURN (Book.Level == "III"); });
// This will display "There are 2 Books for Level III." PROMPT("", "There are " + $scope.ListOfLevel.length + " books for level III.");
|