这里我在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;
}
]);
&#13;
<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>
&#13;
答案 0 :(得分:1)
您正在更改外部范围omega.harish
值,这对于ngRepeat中的所有项都是通用的。而是使用omega.harish
指令创建ngInit
的本地范围副本:
<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>