Wie wird der angularJS-Dienst in eine Steuerung aufgerufen, die nicht in einer Steuerung enthalten ist?Wie kann man den angularJS-Dienst in einen Controller aufrufen, der nicht in einem Controller enthalten ist?
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);
}
}]);
Wenn ich Zugriff auf die Steuerung das Ergebnis von URL zu erhalten, verfolge ich immer Fehler angular.js:13294 Error: [ng:areq] Argument 'productCtrl' is not a function, got undefined
Yo, ich denke es liegt daran, dass du deine App immer wieder neu definierst. Sie tun var app = angular.module ("myApp", []); an wie 3 verschiedene Orte. –