【发布时间】:2018-01-09 12:40:26
【问题描述】:
我正在 Angular 工厂中创建一个函数。我需要这个函数返回承诺。然后我添加其他功能。
SPApp.factory('processing', ['$http', '$rootScope', '$q', function ($http, $rootScope) {
function initialize($scope, status) {
$http({
method: 'GET',
url: '/api/ApiCustomer/GetCustomerDetails'
}).then(function (data) {
if (data.data.ModelValue == null) {
$rootScope.redirectToLogin();
} else {
$scope.CustomerInformation = data.data.ModelValue;
}
}).then(function () {
$http({
method: 'GET',
url: '/api/ApiList/AccountTypeList'
}).success(function (result) {
$scope.accountTypeList = result;
typeOfAccount = result;
});
// get currncy list
$http({
method: 'GET',
url: '/api/ApiList/CurrencyList'
}).success(function (result) {
$scope.currencyList = result;
//jQuery('#ProfileImage').attr('src', "/Content/Images/blank-avatar.jpg");
});
$http({
method: 'GET',
url: '/api/ApiList/BankListByUserType',
}).success(function (result) {
$scope.bankList = result;
});
});
};
return {
initialize: initialize
}
}]);
以及如何调用这个函数作为一个promise然后使用
processing.initialize($scope, true).then(function(){
console.log("hello world");
});
如果你知道这个过程,那么现在不起作用请帮助
【问题讨论】:
标签: javascript angularjs angular-promise