Answer the question
In order to leave comments, you need to log in
How to properly use modules in AngularJS?
Good afternoon.
Decided to play around with AngularJS 1.4.9 as a front for the REST backend.
Studied the sample application phonecat. According to him, you need to use modules as follows:
app.js
var sharePhotoApp = angular.module('sharePhotoApp', [
'userControllers',
'userServices'
]);
var userControllers = angular.module('userControllers', []);
userControllers.controller('UserListCtrl', function ($scope, $http) {
$http({ method: 'GET', url: '/api/users'}).then(function successCallback(response) { $scope.users = response.data;});
});
Error: $injector:modulerr
Module Error
var userControllers = angular.module('sharePhotoApp', []);
angular
.module('sharePhotoApp')
.factory('userService', userService);
userService.$inject = ['$resource'];
function userService($resource) {
return $resource('/api/users/:username', {}, {
query: {method:'GET', params:{username:'@username'}, isArray:true}
});
}
angular
.module('sharePhotoApp')
.controller('UserListCtrl', UserListCtrl);
UserListCtrl.$inject = ['$scope', 'userService'];
function UserListCtrl($scope, userService) {
$scope.apiusers = userService.query();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question