1

在这里,我在 ng-repeat 中有一个 div

<div   ng-class="{div0f:result.subscribed==omega.harish,div0g:!result.subscribed==omega.harish}" id="mecota0f" 
          ng-click="omega.harish=!result.subscribed" >

现在 result.subscribed 是一个来自服务的布尔值,而 omega.harish 是我的简单布尔变量,这个 div 的类将根据 result.subscribed 值

现在我还想更改在 ng-repeat 中创建的一个 div 的活动类,但其他创建的 div 的类一直受到影响。

var app = angular.module('subscribeWho', ['ngResource']);
app.controller('mysubscribeWho', ['subscriberFactory',
  function(subscriberFactory) {

    var self = this;


    subscriberFactory.get({}, function(subscriberFactory) {
      self.subscriberdata = subscriberFactory.user;
    });


    self.harish = false;
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div id="border-forpb" class="col-sm-12 panel panel-default" ng-app="subscribeWho">
  <div class="panel-body" id="artle_panel_body" ng-controller="mysubscribeWho as omega">
    <div ng-repeat="result in omega.subscriberdata">
      <div ng-class="{div0f:result.subscribed==omega.harish,div0g:!result.subscribed==omega.harish}" id="mecota0f" ng-click="omega.harish=!result.subscribed">
      </div>
    </div>
  </div>

4

1 回答 1

1

您正在更改omega.harishngRepeat 中所有项目通用的外部范围值。omega.harish而是创建withngInit指令的本地范围副本:

<div ng-repeat="result in omega.subscriberdata">
    <div ng-class="{div0f:result.subscribed==harish,div0g:!result.subscribed==harish}" id="mecota0f" 
        ng-init="harish = omega.harish"
        ng-click="harish=!result.subscribed">
    </div>
</div>
于 2015-07-14T06:20:32.467 回答