javascript - Reference an element later in angular -


i have 2 images have select 1 or other , class changes depending on select using ng-click. on proceeding next step, make object , store references selected:

$scope.cabinetdetails.cabinettype = {     name: $scope.currentelement.obj.name,     image: $scope.currentelement.obj.image,     ref: $scope.currentelement }; 

$scope.currentelement whatever image had selected , think later access via: $scope.cabinetdetails.cabinettype.ref

let's on step 2 , want make change step one. click breadcrumb go , see step 1 again (this works fine). what i'd happen class changes selected state.

on loading step one, this:

if ($scope.cabinetdetails.cabinettype != null) {     $scope.currentelement = $scope.cabinetdetails.cabinettype.ref; } 

i imagine preselect image had before since ng-repeat simple check in ng-class portion:

<div ng-repeat="obj in currentobject">     <div class="img-select" ng-click="setactive(this)" ng-class="{itemselected : isactive(this)}">       <div align="center">         <img ng-src="resources/images/aventos/{{obj.image}}" />       </div>       <div class="img-title">{{obj.name}}</div>     </div> </div> 

the isactive() function rather simple:

$scope.isactive = function(element) {     return $scope.currentelement === element; } 

i've been trying avoid posting question can't seem figure 1 out. it's reference invalid

the problem this keyword. this not available pass through template.

instead of referencing elements, take step , reference underlying item in repeater. try changing this obj (the object in ng-repeat="obj in currentobject")

ng-click="setactive(obj)" ng-class="{itemselected : isactive(obj)} 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -