In Angular, is there any reason not to list module dependencies with a module declaration?

In all the tutorials and examples I've read regarding Angularjs, they all define modules with an empty list as the second parameter:

angular.module('myModule', []);

I understand that creating a new module requires a second parameter, but I don’t understand why there are no elements in it. The document for angular.module says nothing about what will represent the contents of the list.

However, when defining my application module, I understand that the list contains the modules on which the new module depends, so why is it always empty for application submodules? For example, in my own project, I have a user module that my application depends on:

/* app.js */
angular.module('myApp', [
    'ngCookies',
    'ngResource',
    'ui.bootstrap',
    'ui.router',
    'myApp.system',
    'myApp.users'
]);

angular.module('myApp.system', []);
angular.module('myApp.users', []);

, unit test , , :

Error: [$injector:modulerr] Failed to instantiate module myApp.users due to:
Error: [$injector:unpr] Unknown provider: $stateProvider
http://errors.angularjs.org/1.2.13/$injector/unpr?p0=%24stateProvider
        at /Users/matt/Development/myApp/public/lib/angular/angular.js:3556
        at getService (/Users/matt/Development/myApp/public/lib/angular/angular.js:3683)
        at invoke (/Users/matt/Development/myApp/public/lib/angular/angular.js:3710)
        at /Users/matt/myApp/public/lib/angular/angular.js:3639

, : , :

/* UserControllerTest.js */
describe('UserCtrl', function () {

    var $rootScope,
        $scope,
        controller;

    beforeEach(function () {
        module('ui.router');
        module('myApp.system');
        module('ngResource');
        module('myApp.users');

        inject(function ($injector) {
            $rootScope = $injector.get('$rootScope');
            $scope = $rootScope.$new();
            controller = $injector.get('$controller')('UserCtrl', {$scope: $scope});
        });
    });

    it('should work', function () {
        expect(true).toBe(true);
    });

});

:

/* app.js */
...
angular.module('myApp.users', [
    'ngResource',
    'ui.router',
    'mean.system'
]);

- , ? ​​ - ?

? " ", UserCtrl - unit test?

+4
1

(, , tgst ..). , , , .

, thst, , , "", , , .

, , . ( , .) , , , .

API angular.module, .

, "":

. , . , . . , .

+3

Source: https://habr.com/ru/post/1541910/


All Articles