angularjs - search result with ng-repeate that creates a "add" button (i wan't to not make this button if item already added) -


i think need filter somehow couldn't figure out, code below created i'm sure severely inefficient

$scope.isinlist = function(ident){    var answer = false;    if($scope.list){ // stops firing before has check against       var length = $scope.lister.list[number].ingr.length;       (var i=0; < length; i++){           if($scope.lister.list[number].thing[i].id == ident){ var answer = true;}        }   }   return answer; }; 

in view have ng-hide, function returns false if nothing found..

ng-hide="isinlist(ident)" 

i see can add break; in if when true make little better i'm still hoping sweeter angular way.

edit:

i want remove 1 object in ng-repeat tho.

<ul>   <li ng-repeat="item in list">item.name <button ng-click="addtoanotherlist(item.id)">add</em></li> </ul> 

can make filter remove elem.?

and can filter check array of variables?

i need filter check undefined number of id-s list (to see item isn't in list)

now ng-hide goes of every result in search, , loop checks every value in list don't want duplicates

i second filter solution provided mark offer 1 using ng-hide wouldn't recommend on filter won't work on ie8 , isn't optimized filter option:

$scope.isinlist = function(ident){     return $scope.list &&           $scope.list.thing.filter(function (item) { return (item.id == ident); }).length>0; } 

i wasn't 100% sure array names, general idea work.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -