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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -