大家好我是新的角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