Can't watch a promise
scope.$watch doesn't like promises
by jdmarshall
HTML
<script src="https://code.angularjs.org/1.2.12/angular.js"></script>
<div ng-controller="MyCtrl">
<h2>Can't watch a promise</h2>
<div class="output">Output: {{output}}</div>
<div class="input">
<button ng-click='doClick()'>Click me</button>
</div>
</div>
CSS
body{
padding: 10px;
}
.input, .output {
padding: 10px;
}
.output {
height: 20px;
}
JavaScript
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $q) {
var deferred = $q.defer();
$scope.$watch(deferred.promise, function(value) {
$scope.value = value;
});
$scope.doClick = function() {
deferred.resolve("resolved");
};
}