Hitu Bansal
Hitu Bansal

Reputation: 3137

ng-click under ng-repeat under Angular

I have a ng-repeat under that

i have ng-click

like

<div ng-repeat="">
  <div ng-click="someFunction(name)"></div>
<input type="text" class="common btnDarkGrey editDashboardCategory" data-ng-model="inputCategory" ng-hide="!item.show">
</div>

Now my code

$scope.someFunction = function(name) {
      $scope.scroller.items[index].show = true;
    $scope.inputCategory=name;
    });

Which is working fine on very first click.

When i click second time. my first div pick second value

Any idea ? how to do this

Thanks

Upvotes: 1

Views: 65

Answers (1)

dfsq
dfsq

Reputation: 193251

If you want individual showName values per rendered row you need to set it to individual child scope. Right now you are setting the value to the parent scope showName which is shared by all child scopes ngRepeat creates.

The simple fix is to refer child scope with this keyword:

$scope.someFunction = function(name) {
    var new_name = /* some other calculations */
    this.showName = new_name;
};

Upvotes: 1

Related Questions