大家好我是新的角js,在這裏我想從服務器獲取json到控制器,以便我可以處理數據,但是這裏發生的是第一個警報-11被稱爲然後警報2被調用,在被調用結束提示1,我讀到的承諾,所以我嘗試過,但仍然沒有工作,我希望它發生了一個又一個,請幫我.Thanks提前異步調用角js
sampleApp.controller('firstpage', function ($scope, $q, $http, $templateCache, onlinedata, offlinedata) {
$scope.message = 'This is Add new order screen';
var defer = $q.defer();
defer.promise.then(function() {
$scope.method = 'POST';
$scope.url = 'http://ncrts.com/ncrtssales_compadmin/webservices/user_login';
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
alert($scope.response + 11) //alert11
$http({
method: $scope.method,
url: $scope.url,
cache: $templateCache
}).
success(function (data, status) {
$scope.status = status;
$scope.message = data;
alert($scope.message + 1) //alert1
}).
error(function (data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
$scope.fetch();
})
.then(function() {
alert($scope.message + 2); //alert 2
})
defer.resolve();
//alert($scope.remember)
});
警報3在哪裏? –
對不起警報1,編輯它 – kavinhuh