简体   繁体   中英

Disabling div based on condition in ng-repeat

I'm having an ng-repeat that repeats n times..

HTML:

<div ng-repeat="item in items">
<fieldset ng-disabled="item.activityId==lockResourceId">
<div>Hello</div>
</fieldset>
</div>

Controller:

onWebSocketFired();
  function onWebSocketFired(isLock){
        $scope.lockResourceId=isLock;
}

Here each time the function onWebSocketFired() is fired with the lockResourceId and if that is equals to item.activityId then the div will be disabled. Now this happens for one div inside the ng-repeat on each of the onWebSocketFired() call.But I would like to keep the previously disabled field as it is until and unless any other call has been called. Can anyone suggest a fix please?

Since you want to keep previously disabled fieldsets disabled when new one gets disabled too, you want to store lockResourceId in form of array or object.

<div ng-repeat="item in items">
  <fieldset ng-disabled="lockResourceId[item.activityId]">
    <div>Hello {{ item.activityId }}</div>
    <input type="checkbox">
  </fieldset>
</div>

Then in controller you would use it like this:

$scope.lockResourceId = {};

// Lock some id
$scope.lockResourceId[id] = isLock;

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