Angular: $http promise delay problem
http://angularjs.org/
by gschutz
HTML
<script src="https://code.angularjs.org/1.0.8/angular.min.js"></script>
<div ng-controller="MyCtrl">
Hello, {{name}}!
</div>
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
myApp.controller('MyCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
$scope.name = 'Superhero';
var k = $http.get('/echo/json?teste=go').
success(function(response) {
console.log(response);
$scope.name = response.data;
}).error(function(response) {
$scope.name = response.data;
});
$timeout(function() {
console.log('ho2', k);
k.then(function() {
console.log('ho3');
alert('ho');
})
}, 2000);
}]);