Reputation: 1416
I just learned about $scope.watch here https://stackoverflow.com/a/15113029/2241256.
It says that everything that is used in the view is monitored by angular. So I am wondering what happens when I am using an array containing big objects in a ng-repeat?
Say each object has an attribute: 'name', which is the only thing I use in the list. Will angular still look for changes in the whole object or just look at the 'name' attribute of each object?
Upvotes: 2
Views: 729
Reputation: 1920
AngularJS watches just that name
property of objects because of showing on view. By the way, if those values which is name
property don't need to be directly updated, you can use one-way data binding by adding :: before of variables. Like; ng-bind="::object.name"
. If you do this, AngularJS doesn't watch that variable of your object. Don't worry. If you update your array which contains all of this objects, AngularJS will update those name attributes because of updating array.
You can read this page of docs for one-way data binding.
Upvotes: 3
Reputation: 6124
Just the 'name' attribute.
Only what's used inside of a template (between {{ and }}), or registered manually ($scope.watch('myVar', function () { ... })
) is watched for changes
Upvotes: 2