angularjs - How to change text in element HTML after AJAX response? -
i have html elements on page as:
<div ng-click="add()">1</div> <div ng-click="add()">2</div> <div ng-click="add()">3</div>
how can change text inside <div>
after click add()
, ajax response? tried on jquery.
instead of using static text 1, 2 , 3 bind these like
<div ng-click="add()">{{options.one}}</div> <div ng-click="add()">{{options.two}}</div> <div ng-click="add()">{{options.three}}</div>
this way angular watch if of change on every $digest
. can dynamically set options.one, options.two , options.three , update accordingly.
also, considering how alike div
elements are, should consider putting these in ng-repeat
on options object, in
<div ng-repeat="(key,value) in options" ng-click="add()">{{value}}</div>
and have js starters:
$scope.options = { one: 1, two: 2, three: 3 }
this 1 way go things. write custom directive if accustomed that, depending on needs, easy route.
Comments
Post a Comment