angularjs - setting a this.value in ng-init and accessing it from ng-class not working -
i'm trying attach distinct value child elements of elements created ng-repeat.
div(ng-repeat=" element in array ") div(ng-init=" this.value='zero' " ng-class=" this.value === my.value ? 'match' : 'not' " ) div(ng-init=" this.value='one1' " ng-class=" this.value === my.value ? 'match' : 'not' " )
the $scope.my.value
set dynamically, shown above, want test against this.value
hard-coded element in ng-init
.
but isn't giving me results. maybe this.value
isn't attaching element. doing wrong (i don't know why thought this
work), there alternative want?
i guess crux of question is: there this
/equivalent each element can pin distinct values to?
you can put controller on each element, , initialize value using $index:
html:
<div ng-repeat="element in array" ng-class=" value === my.value ? 'match' : 'not' " ng-controller="elementcontroller"></div>
javascript:
module.controller('elementcontroller', ['$scope', function($scope){ if($scope.$index == 0){ $scope.value = 'zero' } if($scope.$index == 1){ $scope.value = 'one1' } }]);
Comments
Post a Comment