我无法在代码看起来如下的区间内触发事件。
buildApp.controller("StatusCtrl", function ($scope, $http, $rootScope, $interval, CONSTANTS) {
$rootScope.$on('changestatus', function(event,data) {
$scope.loading = true;
$scope.id = data.id;
//fire event if got success or terminate if reached 10 minute of try
$scope.getstatus = function(){
var req = {
method : 'GET',
url: CONSTANTS.API.HTTPSERVER + CONSTANTS.API.BASEURL + CONSTANTS.API.BUILD.SELF + CONSTANTS.API.BUILD.GETCURRENTSTATUS + $rootScope.id
}
$http(req).
success(function (data, status, headers, config) {
$rootScope.status = data.status;
}).
error(function (data, status, headers, config) {
$rootScope.status = "failed";
});
};
var promise;
promise = $interval(function () {
$scope.getstatus();
if ($rootScope.status == "BuildSucceeded") {
console.log($rootScope.status);
$interval.cancel(promise);
$rootScope.$emit('buildinfo', {id: $scope.id});
}
else if (promise == 600000) {
$scope.loading = false;
$interval.cancel(promise);
}
}, 30000);
})
});
关于代码的快速解释是我在常规的30秒间隔遇到api如果我获得成功消息我将触发其他事件但是即使成功第二个事件也没有被解雇$rootScope.$emit('buildinfo', {id: $scope.id});
此代码未成功执行