angularjs - Changing class in the ng-repeat using the index value -


here have div in ng-repeat

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

now here result.subscribed boolean value coming services , omega.harish simple boolean variable class of div according result.subscribed value

now want change active class of 1 of div created in ng-repeat class of other created divs kept getting affected.

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 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>

you changing outer scope omega.harish value common items in ngrepeat. instead create local scope copy of omega.harish nginit directive:

<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> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -