Can you say why it is recommended to add dependency modules to module creation?
I tried to run the code without adding TodoApp.controllers and TodoApp.services modules . Despite the fact that I deleted them, everything went fine. (I call the service through these two files)
app.js
var TodoApp = angular.module("TodoApp", [
"ngRoute",
"ngResource",
"TodoApp.controllers",
"TodoApp.services"
]).
config(function ($routeProvider) {
$routeProvider.
when('/', { controller: "listCtrl", templateUrl: 'list.html' }).
otherwise({ redirectTo: '/' });
});
Update
Thanks for your reply!:)
Unfortunately, these files do not have a common variable:
That was the reason I did not understand the problem. For me, this code is stored nowhere. Maybe because of the dot notation in the name?
controller.js
angular.module('TodoApp.controllers', []).
controller('listCtrl', function ($scope, $location, todoApiService) {
$scope.todos = todoApiService.getMyTodos().query();
});
services.js
angular.module('TodoApp.services', []).
factory('todoApiService', function ($resource) {
var todoApi = {};
todoApi.getMyTodos = function () {
return $resource('/api/todo/:id', { id: '@id' }, { update: { method: 'PUT' } });
};
return todoApi;
});
source
share