コントローラに含まれていないコントローラにangularJSサービスを呼び出す方法はありますか?コントローラに含まれていないコントローラにangularJSサービスを呼び出す方法は?
productCtrl.js
var app = angular.module('myApp',[]);
app.controller('productCtrl',['$scope','productService', function ($scope,campaignService)
{
$scope.getLocations = function() {
productService.getPorduct(response,status);
}
}]);
productService.js
var app = angular.module("myApp", []);
app.service('productService', ['ajaxService', function (ajaxService) {
this.getPorduct = function (successFunction, errorFunction) {
ajaxService.AjaxGet("http:location.com/product#?clientid=10",
successFunction, errorFunction);
};
}]);
ajaxService.js
var app = angular.module("myApp", []);
app.service('ajaxService', ['$http', 'blockUI', function ($http, blockUI) {
this.AjaxGet = function (route, successFunction, errorFunction) {
blockUI.start();
setTimeout(function() {
$http({ method: 'GET', url: route }).success(function (response, status, headers, config) {
blockUI.stop();
successFunction(response, status);
}).error(function (response) {
blockUI.stop();
errorFunction(response);
});
}, 1000);
}
}]);
私はURLからの結果を得るために、コントローラにアクセスし、私は次のエラー angular.js:13294 Error: [ng:areq] Argument 'productCtrl' is not a function, got undefined
あなたはあなたのアプリを継続的に再定義しているからだと思います。あなたはvar app = angular.module( "myApp"、[]);を実行しています。 3つの異なる場所のように。 –