プロセス: サービスでhttpGetメソッドを呼び出して4つのhttpget呼び出しを呼び出そうとしましたが、最初のhttpget呼び出しはエラーを返し、残りの呼び出しは成功メッセージを返します。例外を処理するために、angularjsの1つのサービスでhttp getコールのリストを作成できませんか?
問題:私は私のコントローラにはなく、コンソールエラーはTypeErrorてその誤差関数の応答を呼び出そう:誤差関数は関数ではありません
コード:
myController:
app.controller('myCtrl',["myService",function(myService){
var id =10;
$scope.getTemp = function() {
myService.getTemplate(id, $scope.getTemplateResponse, $scope.ErrorResponse);
};
$scope.getTemplateResponse= function (response) {
$scope.bodyTemplate = response.Value;
};
$scope.ErrorResponse = function(error){
window.location.href = "Error#?" + error;
}
$scope.getTemp();
}]);
myServiceという:
app.service("myService", ["ajaxService", function (ajaxService) {
this.getTemplate= function (id, successFunction, errorFunction) {
ajaxService.Get("http://gettempaltes.com/api/id="+id, successFunction, errorFunction);
};
}]);
ajaxService:
app.service("ajaxService", ["$http", function($http) {
this.Get= function (route, successFunction, errorFunction) {
$http.get(route).success(function (response, status) {
successFunction(response, status);
}).error(function(response) {
errorFunction(response);
});
};
}]);
これは、行27:29を指していますか? – Aravind