javascript - AngularJS — Passing object/object property to be $watched into $scope.$watch -
deep watching on large objects performance killer—so i'd able pass dynamic object/property watchexpression parameter of $scope.$watch function, whenever invoke action changes particular object or property.
i have bunch of different objects , don't want set watches of them.
for example:
var watchingfunction = function (objecttobewatched) { $scope.$watch(function (objecttobewatched) {return objecttobewatched;}, function(newvalue, oldvalue) { if (newvalue !== oldvalue) {...}; }, true); $scope.object = true; $scope.changemyobject = watchingfunction(object); html
<input type="checkbox" ng-model="object" ng-change="changemyobject()"> i believe wouldn't work because invoking function watchingfunction() runs $scope.$watch() once? if define $scope.$watch on $scope (instead of wrapped inside watchingfunction() continually watching $scope.$watch's watchexpression?
if case, there creative things can return value watchexpression takes outside parameter instead of explicitly declaring object within $scope.$watch's watchexpression?
thanks bunch!
edit additional clarity—i'm using $scope.$watch make $scope.$broadcast's scope every time value on current scope changes.
as $scope.$watch documentation states watchexpression called multiple times (even in 1 digest cycle), if passed object there , change object not work. why better pass string watchexpression
$scope.$watch('object', function() {...} ) or change inside object.
<input type="checkbox" ng-model="object.value" ng-change="changemyobject()">
Comments
Post a Comment