typescript - angularjs $watch watchExpression with promise is going into infinite digest loop -


angularjs watch method watchexpression returning promise.

$scope.$watch(function() { var promise = myservice.getmethod(); promise.then(function(value){   return value; }) }, function(newvalue, oldvalue) { console.log("new value:", newvalue); }); 

typescript call method promise.

public getmethod(): angular.ipromise<any> {   var deferred: angular.ideferred<any>   = this.$q.defer();   localforage.getitem(‘key’).then(function(value) {     deferred.resolve(value);   }).catch(function(err) {     deferred.reject();     console.log(err);   });   return deferred.promise; } 

i want return "value" localforage promise in myservice return $watch watchexpression function.

you can use localforage.bind directly bind storage value scope:

localforage.bind($scope, {key: 'key', scopekey: 'sckey'}); 

and use two-way binded $scope.sckey.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -