angularjs - creating a global variable that is assigned within an ng-repeat -
i trying ng-click assign variable (success) inside ng-repeat , use value outside of ng-repeat(failure) follows:
<div class="stocksnav col s1"> <div class="mystocklist" ng-repeat="stocksinportfolio in ctrl.myportfolio.stocksinportfolio"> <ul> <li style="position: relative"><a href ng-click="ctrl.tab = stocksinportfolio.stock._id">{{stocksinportfolio.stock.name | limitto:10}}</a></li> </ul> <div class="mystockview" ng-show="ctrl.tab === stocksinportfolio.stock._id"> <div class="{ active:ctrl.tab === stocksinportfolio.stock._id }"> </div> </div> </div> </div> <div ng-include="'/app/dashboard/partials/myindividualstock.html'"></div>
the partial wants call ctrl.tab use it's click event assigned values, such if ng-click on other instance of ng-repeat function ctrl.tab variable reassign, ctrl.tab assignment not persist outside of ng-repeat div. thought?
the ng-repeat
directive (as many other directives) creates new scope, , access parent's scope variable, needs object. in other words, instead of ctrl.tab
, initialize object $scope.something = {}
in controller, use ctrl.something.tab
in template (replace something
name proper application).
Comments
Post a Comment