Filtering an Angular 1.2 ng-repeat with “track by” by a boolean property
The track by needs to be at the end of the expression: <li ng-repeat=”person in attendees | filter: {arrived: false } track by person.id”>
The track by needs to be at the end of the expression: <li ng-repeat=”person in attendees | filter: {arrived: false } track by person.id”>
We now have a proper support for this, please see: AngularJs Commmit with this change you can now do: <table> <tr ng-repeat-start=”item in list”> <td>I get repeated</td> </tr> <tr ng-repeat-end> <td>I also get repeated</td> </tr> </table>
The syntax is just a little off, try: <li class=”list-group-item” ng-repeat=”question in newSection.Questions | filter:{ Id: ‘!-1’}” ng-mouseenter=”hover = true” ng-mouseleave=”hover = false”> <div href=”#” editable-text=”question.Text”>{{question.Text}}</div> </li> See a little JSFiddle: http://jsfiddle.net/U3pVM/3845/ Edit: Example with variables: <script> var invalidId = ‘-1’; </script> <li class=”list-group-item” ng-repeat=”question in newSection.Questions | filter:{ Id: ‘!’ + invalidId}” ng-mouseenter=”hover = … Read more
As @Maxim Shoustin suggested, the best way to achieve what you want would be to use a custom filter. But there are other ways, one of them being to use the ng-if directive on the same element were you put the ng-repeat directive (also, here’s the plunker): <ul> <li ng-repeat=”player in players” ng-if=”player.name_key!=’FirstPerson'”></li> </ul> This … Read more
Try this: <tr ng-repeat=”player in players | filter:{id: player_id, name:player_name} | filter:ageFilter”> $scope.ageFilter = function (player) { return (player.age > $scope.min_age && player.age < $scope.max_age); }
Okay, through a lot of the comments above, I have discovered the confusion. First, a couple of points of clarification: ngRepeat does not affect your chosen isolate scope the parameters passed into ngRepeat for use on your directive’s attributes do use a prototypically-inherited scope the reason your directive doesn’t work has nothing to do with … Read more
Remove the display:none, and use ng-show instead: <ul class=”procedures”> <li ng-repeat=”procedure in procedures | filter:query | orderBy:orderProp”> <h4><a href=”#” ng-click=”showDetails = ! showDetails”>{{procedure.definition}}</a></h4> <div class=”procedure-details” ng-show=”showDetails”> <p>Number of patient discharges: {{procedure.discharges}}</p> <p>Average amount covered by Medicare: {{procedure.covered}}</p> <p>Average total payments: {{procedure.payments}}</p> </div> </li> </ul> Here’s the fiddle: http://jsfiddle.net/asmKj/ You can also use ng-class to toggle … Read more
Whenever you do some form of operation outside of AngularJS, such as doing an Ajax call with jQuery, or binding an event to an element like you have here you need to let AngularJS know to update itself. Here is the code change you need to do: app.directive(“remove”, function () { return function (scope, element, … Read more
In Template <td>Total: {{ getTotal() }}</td> In Controller $scope.getTotal = function(){ var total = 0; for(var i = 0; i < $scope.cart.products.length; i++){ var product = $scope.cart.products[i]; total += (product.price * product.quantity); } return total; }
You can track by $index if your data source has duplicate identifiers e.g.: $scope.dataSource: [{id:1,name:’one’}, {id:1,name:’one too’}, {id:2,name:’two’}] You can’t iterate this collection while using ‘id’ as identifier (duplicate id:1). WON’T WORK: <element ng-repeat=”item.id as item.name for item in dataSource”> // something with item … </element> but you can, if using track by $index: <element … Read more