# Install angular-cli
npm install -g @angular/cli
# Create brand new project
ng new my-new-project
# What did that command just do?
cat package.json
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
Type | Usage | Example |
---|---|---|
Microtask | Guaranteed to run once and immediately | promise.then() |
Macrotask | Work to be done later that is not guaranteed to run. Able to cancel. | setTimeout, setInterval, requestAnimationFrame |
EventTask | Task may execute zero or more times with an unknown delay | MouseClick, KeyboardEvent, 'on' properties, ... |
API | Usage |
---|---|
Zone.current | Returns currently active zone |
zoneObj.fork(ZoneSpec) | Create a new child zone. ZoneSpec |
zoneObj.get(key) | Returns value of property with given key |
zoneObj.getZoneWith(key) | Searches parents for zone with given key |
API | Usage |
---|---|
zoneObj.run(fn) | Run function within zoneObj |
zoneObj.runGuarded(fn) | Run function within zoneObj and catch all exceptions |
zoneObj.wrap(fn) | Returns function wrapping fn and restoring zone and this |
Hook | Usage |
---|---|
onFork | Called when the zone is forked. |
onIntercept | Called when wrap() is called |
onInvoke | Called when run() callback is executed |
onHandleError | Called when an error is handled by zone |
onScheduleTask | Called when a task is scheduled |
onInvokeTask | Called when a scheduled task is run |
onCancelTask | Called when a scheduled task is canceled |
onHasTask | Called when a task queue is modified |
constructor() {
this._zone.onMicrotaskEmpty.subscribe(
{next: () => { this._zone.run(() => { this.tick(); }); }});
}
/**
* Invoke this method to explicitly process change detection
* and its side-effects.
* ...
*/
tick(): void {
// ...
this._views.forEach((view) => view.detectChanges());
// ...
}
API | Usage |
---|---|
onUnstable | EventEmitter that notifies when code begins to execute in the zone. |
onMicrotaskEmpty | EventEmitter that notifies when microtask queue is empty. May fire more than once. |
onStable | EventEmitter that notifies when the last onMicrotaskEmpty fires. |
run() / runGuarded() | Execute code within NgZone. Same as zone.js. |
runOutsideAngular() | Execute code within parent zone, will not trigger change detection. |
ChangeDetectorRef