简体   繁体   中英

How to restrict ng-repeat with ng-if

<div ng-repeat="post in posts" ng-if="post.type !='article'">
  <h1>{{post.title}}</h1>
</div>

in the above code that will restrict only when 'artical' comes to the list then it will restrict.but In my scenario I have drop down that will add dynamically.Here I want to restrict already selected value should not be visible in the next added drop down.

JSFiddle

您可以对ng-repeat集合使用filter ,然后在其中动态传递type值。

ng-repeat="post in posts | filter: { type: selectedValue }"

Try this solution :

HTML:

<select ng-model="personalDetail.fname" ng-options="x for x in allowedNames(personalDetail.fname)">
</select>

Javascript:

$scope.allowedNames = function(current){
    var temp = $scope.names.filter(function(x){ 
        return $scope.personalDetails.map(function(x){ return x.fname}).indexOf(x) == -1 
    });
    temp.push(current);
    return temp;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM