javascript - ng-class only for current scope in ng-repeat angularjs -


i'm having trouble ng-class part of angularjs.

the thing figured out adding class after success or error allll buttons ng-click on.

but want add/change class of clicked element. possible in way?

<section ng-repeat="user in users">      <button class="btn" ng-click="myfunction(user);" ng-class="{invalid:errors,done:success}"></button>  </section>  <script> function userscontroller($scope, $http) {     $http.get('/users.json').success(function(users) {         $scope.users = users;          $scope.errors = false;         $scope.success = false;     });      $scope.myfunction = function(user) {         $http.post('/myurl/'+user.id, student)         .success(function(data, status, headers, config) {             // $scope.success = true;             user.success = true;         })         .error(function(data, status, headers, config) {             // $scope.errors = true;             user.errors = true;         });     } } </script> 

what want current scope, doesn't work.

my function work, except passing ng-class values trough.

another solution:

<section ng-repeat="user in users">     <button class="btn" ng-click="myfunction(user)"              ng-class="{invalid: isinvalid(user), done: issuccess(user)}">{{user.name}}</button> </section> 

so create isinvalid , issuccess functions , pass in current user object:

$scope.issuccess = function(user) {     return user === $scope.state.success; };  $scope.isinvalid = function(user) {     return user === $scope.state.errors; }; 

these 2 functions can decide if current user invalid or successful. example when there error set this:

$scope.state = {     success: false,     errors: user }; 

demo: http://plnkr.co/edit/rdjy9vsrkhao0cfnb6av?p=preview


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -