AngularJS: Filter Too Lax - incorrect display -


i have object of attachments returned sharepoint custom list each named projectid | requestid | taskid | filename.

i trying filter according needs (only 1 id present filename , rest 0 unless there sharing going on) when filter pid (project id) == 1, displays pid 1 , 17. how tighten filter match exact?

here plunkr.

here html:

<body ng-controller="mainctrl">     <h3>all attachments:</h3>     <ul>       <li ng-repeat="att in attachments">{{att.title}}</li>     </ul>     <hr />     <h3>attachments project #1</h3>     <ul>       <li ng-repeat="pat in fstproj = (attachments | filter:{pid:'1'})">{{pat.title}}</li>     </ul>   </body> 

and here javascript:

var app = angular.module('app', []);  app.controller('mainctrl', function($scope, catfactory) {    $scope.attachments = catfactory.getattachments();   }); 

the filter filter uses string-matching. sinc eyou want compare exact numbers, can filter user-defined function:

<li ng-repeat="pat in attachments | filter:bypid">{{pat.title}}</li>  $scope.bypid = function (item) {     return item.pid === 1; } 

see, also, short demo.


update:

of course, if willing use more recent version of angular (not 1.0.* branch) (which absolutely should), there third paramter passed filter, in order strict matching (instead of substring):

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js" ...> ... <li ng-repeat="pat in attachments | filter:{pid:1}:true">{{pat.title}}</li> 

in case, nothing else needs changed.

see, also, other demo.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -