0
我使用AngularJS v1.0.7沒有方法和這裏的如何我設置的服務:AngularJS服務:被錯誤有「保存」
angular.module('myAngularJSApp.services',['ngResource'])
.factory('RegisterNumber', ['$resource', function($resource) {
return $resource('../api/register/number/:id', {id:'@id'});
}])
.factory('RegisterChannel', ['$resource', function($resource) {
return $resource('../api/register/channel/:id', {id:'@id'});
}])
,這裏是我的控制器:
angular.module('myAngularJSApp')
.controller('RegisterCtrl', ['$scope', '$location', 'RegisterNumber', 'RegisterChannel', function ($scope, RegisterNumber, RegisterChannel) {
$scope.step = 1;
$scope.advanceStep = function(_step){
var AcctNum = RegisterNumber
, AcctChn = RegisterChannel
switch(_step){
case 1:
var acctNum = AcctNum.save({ // This line throws the error
id : $scope.security_number
},
// SUCCESS
function(){
$scope.showError = false;
advance(_step);
},
// ERROR
function(response){
$scope.showError = true;
});
break;
case 2:
var acctChn = AcctChn.save(
{ id : $scope.channel},
// SUCCESS
function(response){
$scope.showError = false;
advance(_step);
},
// ERROR
function(response){
});
break;
}
}
}]);
而且我得到這個錯誤:
TypeError: Object #<Object> has no method 'save'
at Object.$scope.advanceStep ...
我做了一些檢查:console.log(AcctNum)
給人以LocationHashbangUrl
對象。然而,奇怪的是console.log(AcctChn)
給出:
function Resource(value){
copy(value || {}, this);
}
這是正確的。我已經搜索了類似的問題&嘗試了答案(here,here和here),但我一直得到相同的錯誤。我錯過了什麼?有什麼想法嗎?
糟糕!錯過了那一個。謝謝! – Dida
我的救世主......! –
我們不能重寫控制器定義爲; angular.module('myAngularJSApp') .controller('RegisterCtrl',function($ scope,RegisterNumber,RegisterChannel){...} ); – Aakash