我收到此错误:“类型错误 - 无法设置属性选择'未定义的”在存储库函数的承诺。将对象数组添加到角度作用域对象 - 类型错误
变量obj包含一个对象数组。
.then(function (obj) {
// this works...
var abc = {};
abc.title = "hello";
abc.obj = obj;
// this doesn't work...
$scope.modelData = {};
$scope.title = "Import";
$scope.message = "Please select a Purchase Request"
$scope.select = obj; // <-- TypeError -- cannot set property 'select' of undefined'
它提高了角度函数期间的错误,所以我确信它是Angular不喜欢它。
===编辑为包含更多的代码。
这里是我的控制器中的相关内容:
var app = ipoModule.controller("ipoController",
function ($scope, $compile, $window, $http, $q, $log, ipoRepository, $routeParams, limitToFilter, $modal, ngTableParams) {
$scope.ipoRepository = ipoRepository;
//... not-relevant stuff
$scope.PRList = ipoRepository.getMvpPRs($scope.POHeader.warehouseId)
.then(function (obj) {
var modelData = {};
modelData.title = "MVP Import";
modelData.message = "MVP Purchase Request ID";
modelData.select = obj;
$scope.modalData = modelData;
// then do more stuff but it breaks before that...
})
.catch(function (err) {
$scope.HandleErrorDoc('Search Error', err)
});
})
,这里是我的一些库的
ipoModule.factory('ipoRepository', function($resource, $http) {
var genericGet = function(params, URL) {
return $http.get(URL, {
params: params
}).then(function(res) {
if (res.data) {
return res.data;
} else {
return null;
}
});
};
return {
getSearchResults: function(txt, chk, myPO) {
return genericGet({
SearchText: txt,
excludeCompleted: chk,
MyPO: myPO
}, '/Search/GetSearchResults');
},
getMvpPRs: function(id) {
return genericGet({
id: id
}, '/MvpUtility/GetMvpPRs')
}
}
});
...现在...模块
var ipoModule = angular.module('ipoModule', ['ngRoute', 'ngResource', 'ngGrid', 'ui.bootstrap', 'unsavedChanges', 'ngIdle', 'ngTable'])
.config(function($routeProvider, $locationProvider, unsavedWarningsConfigProvider) {
//$locationProvider.html5Mode(true);
unsavedWarningsConfigProvider.useTranslateService = false;
});
你能添加一个更大的代码片段吗? '$ scope'被注入了吗? – joemfb 2015-04-02 16:54:50
听起来像'$ scope'是未定义的。告诉我们你的控制器的其余部分 – Tom 2015-04-02 16:59:52
你能否请添加console.log(obj)? obj中有些问题。 – Samir 2015-04-02 17:10:36