What Is The Meaning Of The Square Brackets In “.module("modulename", […])” Of AngularJS
I just saw an example of routing in AngularJS. I would like to know the relation ship between dependency 'ngRoute' and module mainApp, in synatx var mainApp = angular.module('mainA
Solution 1:
In angular, when defining a module
(creating it), you pass it the names of other module
s it depends on as an array (in square brackets).
In your example, the mainApp
-module
depends on the ngRoute
-module
, making the components of ngRoute
(directives, services, factories, values...) available for dependency injection for the components in mainApp
. To define a module
that does not depend on any other modules, you pass an empty array ([]
) See the angular documentation for some more info on modules
Solution 2:
[...]
defines an array
In the angular case.
mainApp
is a main module( main array) and ngRoute
is a sub module(like array of object).
The sample is
var ngRoute=[];//{}
var mainApp=[ngRoute];// now the `mainApp` includes the `ngRoute`
Post a Comment for "What Is The Meaning Of The Square Brackets In “.module("modulename", […])” Of AngularJS"