我正在学习Angular JS并拥有以下工厂。在将其记录到控制台时,我可以看到返回的数据。
app.factory('SelectOptionFactory', ['$http', '$q', 'DatabaseService', function ($http, $q, DatabaseService) {
'use strict';
//variables
var routeControllerURL = 'SelectOption/';
return {
getSelectOptions: function getSelectOptions() {
var apiRouteMember = [];
apiRouteMember.push(routeControllerURL + 'SelectOptionList')
apiRouteMember.push('APPLICATION_STATUS');
DatabaseService.getDataFromAPIRoute(apiRouteMember).then(function (response) {
return response.data;
});
}
}
}]);
然后我的控制器具有以下功能,在按钮点击时调用该功能,我收到此错误:
angular.js:13920 TypeError: Cannot read property 'then' of undefined
at m.$scope.addInventoryApplicationDetails (Inventory_Controller.js:228)
$scope.addInventoryApplicationDetails = function () {
$scope.applicationStatus = [];
SelectOptionFactory.getSelectOptions().then(function (data) {
$scope.applicationStatus = data;
}).catch(function () {
$scope.error = 'unable to get the data';
});
};
我做错了,因为.then()
方法没有返回通过successCallback,errorCallback的返回值解析或拒绝的新promise?
答案 0 :(得分:2)
MixinA
没有返回任何内容。你只需要回复承诺
getSelectOptions()