I have this code.
http://jsfiddle.net/0tgL7u6e/
JavaScript
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.nameFilter = '';
$scope.contacts = [
{name: 'GHI'},
{name: 'DEF'},
{name: 'ABC'},
{name: 'JKL'}
];
}
View
<div ng-controller="MyCtrl">
<div><input type="text" ng-model="nameFilter" placeholder="Search..." /></div>
<p ng-repeat="contact in contacts track by $index | filter: nameFilter | orderBy: name">{{ contact.name }}</p>
</div>
I don't know why the order is not working and why the filter is not working.
At another question, I've read about something that objects can't be filtered or ordered. But I have an array of the objects above. Also, it should work!?
What's the problem?
The ng-repeat values can be filtered according to the ng-model in AngularJS by using the value of the input field as an expression in a filter. We can set the ng-model directive on an input field to filter ng-repeat values.
The *ngFor directive in Angular is like the ng-repeat directive in AngularJS. It repeats the associated DOM element for each item in the specified collection.
NEST TWO ng-repeatThe first ng-repeat in the tr tag will create the rows and the second one in the td tag will create one column per element in the collection. By using one ng-repeat for the row and an other for the column, the rows and the columns of your table is now driven by a subset.
Definition and Usage The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.
To use tracking with filters, the track by expression has to be added after the filter.
<p ng-repeat="contact in contacts | orderBy: 'name' | filter: nameFilter track by $index">{{ contact.name }}</p>
Here is the working fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With