Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to single bind in ui-sref?

I am doing ng-repeat of a list that look like this:

<div ng-repeat="x in myCtrl.data" ui-sref="app.detail({id: x.id})">
    <img ng-src="{{::x.image}}">
    <h2>{{::x.name | characters:35}}</h2>
</div>

When I monitor the watcher, I found that the watcher increases when the list getting longer. If I remove the {id: x.id} from the ui-sref, no matter how long the list is, the number of watcher always remains the same.

So, my question is how can I do a single binding in ui-sref?

like image 715
user1995781 Avatar asked Aug 16 '26 10:08

user1995781


2 Answers

ui-sref="app.detail(::{id: x.id})

no redirects nothing, one line code one time binding

like image 148
user3205479 Avatar answered Aug 18 '26 23:08

user3205479


Yes, if you look at API you will come to know that, it adds watcher from this line & you can't avoid that.

You could get rid of that watcher by do the redirection to state thing by your own, like you could have ng-click="redirect('app.detail', {id: x.id})" event there instead of having ui-sref directive, and from redirect method you could redirect to the state using $state.go.

Code

$scope.redirect = function(stateName, param){
    $state.go(stateName, param)
}
like image 33
Pankaj Parkar Avatar answered Aug 18 '26 23:08

Pankaj Parkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!