An open API service indexing awesome lists of open source software.

https://github.com/normandy72/modules

Modules in AngularJS. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
https://github.com/normandy72/modules

angular angularjs css css3 html html5 javascript js

Last synced: about 1 month ago
JSON representation

Modules in AngularJS. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.

Awesome Lists containing this project

README

          

# Modules in AngularJS
## Steps to create modules
#### Step 1: Declare / Create Module
```
angular.module('module1', []);
```
`.module` - declare module
`'module1'` - unique module name
`[]` - dependencies

##### Specify other modules as dependencies
```
// no dependencies
angular.module('module1', []);
angular.module('module2', []);

// dependent on module1 and module2
angular.module('module3', ['module1', 'module2']);
```
#### Step 2: Declare Module Artifacts
```
angular.module('module1')
.controller('MyController', MyController);
```
`('module1')` - second argument missing!
#### Step 3: ng-app='MainModule'
```

...

```
## Splitting Javascript into Several Files
```

```
`` - declare / create 'module1'
`` - retrieve & use to declare Controller

##### Also correct variant
module2 before module1
```

```
##### Incorrect variant
because component uses module2 (using module2 before it's created)
```

```
## Configuration and Run Blocks
#### .config
```
angular.module('module1')
.config(function(){
...
});
```
`function()` - inject only Providers and Constants
#### .run
```
angular.module('module1')
.run(function(){
...
});
```
`function()` - inject only Instances (like Services) and Constants
***
#### _Summary_
* `angular.module` method takes 2 arguments to create a module:
* name of module;
* array of string module name dependencies.
* `angular.module` method with just name of module retrieves the previously created method. Then, you can declare components, controllers, etc., on it.
* `module.config` method fires before module.run method.
* All dependency modules get configured first.
* It doesn't matter which modules are listed first as long as module declarations are listed before artifact declarations on that module.
***