javascript - Forcing $scope.$watch to only fire once -



javascript - Forcing $scope.$watch to only fire once -

$scope.$watch('text', function () { $scope.obj = new text($scope.text); console.log('hi!'); }); // hi! // hi!

how can prevent $watch firing multiple times? not defining or changing $scope.text @ time before snippet above. attempted test newvalue !== oldvalue did not alter anything.

edit:

i have narrowed downwards issue directive issue. input box beingness watched within custom directive, reason effecting ng-model of input box multiple times.

$scope.$watch(..) returns unbind function, this:

var unbind = $scope.$watch('text', function () { $scope.obj = new text($scope.text); console.log('hi!'); unbind(); });

this cause fire, , unbind after firing once.

edit:

for valuechanges:

$scope.$watch('text', function (nv, ov) { if (ov != nv) { $scope.obj = new text($scope.text); console.log('hi!'); } });

javascript angularjs

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -