【发布时间】:2016-01-16 17:23:48
【问题描述】:
这是我在 factory.js 中写的:
app.factory('CustomerCompany', function($resource){
return $resource('/customer_companies/:id.json', {id: "@_id"}, {
'query':{method: 'GET', isArray:false},
'getByCustomerAccount':{
method: 'GET',
params: {customer_account_id: customer_account_id},
isArray:true,
url:'/customer_companies/get_by_account/:customer_account_id.json'
}
});
});
因为我想获取属于特定 customer_account 的 customer_companies 列表,所以我需要提供 customer_account_id。
在我的 controllers.js 中,
app.controller('customerAccountEditController', function($scope, CustomerCompany) {
$scope.data = {};
var path = $location.path();
var pathSplit = path.split('/');
$scope.id = pathSplit[pathSplit.length-1];
var customer_account_id = $scope.id;
$scope.list_of_companies = [];
CustomerCompany.getByCustomerAccount({customer_account_id: customer_account_id}, function(data){
console.log(data);
//$scope.list_of_delegates.push(data);
});
});
我得到一个未定义的 customer_account_id。
我哪里做错了?
【问题讨论】:
标签: javascript angularjs rest angularjs-service angular-resource