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.
- Host: GitHub
- URL: https://github.com/normandy72/modules
- Owner: Normandy72
- Created: 2023-01-19T10:31:50.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T12:37:19.000Z (over 3 years ago)
- Last Synced: 2025-07-03T20:43:09.892Z (11 months ago)
- Topics: angular, angularjs, css, css3, html, html5, javascript, js
- Language: JavaScript
- Homepage:
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.
***