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
Post a Comment