javascript - How can I go to next item of array in Angularjs expression? -
i have been trying dynamically change array number of expression. initial state:
<p class="title text-center">{{data[0].title}}</p> <p class="subtitle text-center">{{data[0].sub_title}}</p>
data
array returned http
request. want when click or swipe element on page jumps second item in data array, e.g.:
<p class="title text-center">{{data[1].title}}</p> <p class="subtitle text-center">{{data[1].sub_title}}</p>
i have been trying make expression in expression, think that wrong. also, have tried adding variable $scope
in controller:
$scope.update = function (whateverispassedinfromotherfunction){ var item = whateverispassedinfromotherfunction; return "data["+whateverispassedinfromotherfunction+"].sub_title"; }
and in html
<p class="subtitle text-center">{{update}}</p>
but not make sense angular , me neither :).
anyone knows solution?
make current index variable, initted 0, , increment it. can increment either making function on controller increments it, or directly in ng-click / ng-swipe.
<span ng-click="idx++"> <!-- init idx 0 in controller --> <p class="title text-center">{{data[idx].title}}</p> <p class="subtitle text-center">{{data[idx].sub_title}}</p> </span>
Comments
Post a Comment