You're not correctly injecting your service into your controller.
Change it to
app.controller('PageController', ['$scope', '$http', 'PageService', function($scope, $http, PageService) {
Вопрос
Here is how I created my service
app.factory('PageService', function($http) {
return {
getPageTemplate: function(url) {
return $http.get(urlBuilder(url));
}
}
})
And here is my controller
app.controller('PageController', ['$scope', function($scope, $http, PageService) {
$scope.changePanel = function(url) {
PageService.getPageTemplate(url).success(function(data) {
console.log(url);
})
}
}])
changePanel will be called when ng-click fires.
This is the message am getting
TypeError: Cannot call method 'getPageTemplate' of undefined
Решение
You're not correctly injecting your service into your controller.
Change it to
app.controller('PageController', ['$scope', '$http', 'PageService', function($scope, $http, PageService) {