Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit b4dc858

Browse files
committed
docs(inheritance): sample
1 parent 4253378 commit b4dc858

17 files changed

+318
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/*.ngfactory.ts
2+
**/*.ngsummary.json
3+
**/*.metadata.json
4+
dist
5+
!app/tsconfig.json
6+
!rollup-config.js
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Angular Inheritance Sample (draft)
2+
3+
The AOT Cookbook sample was the starting point.
4+
This sample runs in both JIT and AOT
5+
6+
With AOT you have to re-build after each change.
7+
With JIT you can develop on the fly as we usually do.
8+
9+
## Inheritance experiments
10+
Look at `sub.component.ts` to see the experiments in metadata inheritance.
11+
12+
13+
## Building it
14+
15+
The original source is in https://github.com/angular/angular.io/pull/3096 along with
16+
tools and configs to build it in JIT and AOT.
17+
You'll need knowledge of the Angular docs sample development practices to do it.
18+
19+
Commands to run:
20+
21+
```
22+
# compile with AOT, then rollup. Noisy.
23+
npm run build:aot
24+
25+
# start server and JIT/TS watching as usual
26+
npm start
27+
```
28+
The browser displays the JIT version (`index.html`) by default.
29+
You can tell by looking at the browser tab (it says "JIT:..."), in the console, and in the page header.
30+
31+
To see the AOT version, put `index-aot.html` in the address bar.
32+
You can tell by looking at the browser tab (it says "AOT:..."), in the console, and in the page header.
33+
34+
## Running it
35+
36+
I like to have two console windows open:
37+
38+
1. Running `npm start` (after once having run `npm run build:aot`)
39+
40+
1. Where I periodically re-run either `npm run tsc` or `npm run build:aot` after a change that works in JIT
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @fileoverview This file is generated by the Angular 2 template compiler.
3+
* Do not edit.
4+
* @suppress {suspiciousCode,uselessCode,missingProperties}
5+
*/
6+
/* tslint:disable */
7+
8+
export const styles:any[] = ['#speak[_ngcontent-%COMP%] { font-style: italic; color: blue; }'];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- #docregion -->
2+
<h1>Angular Inheritance ({{buildMode}})</h1>
3+
<base-comp speaker="Paul"></base-comp>
4+
<sub-comp speaker="Helen"></sub-comp>
5+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'my-app',
7+
templateUrl: './app.component.html'
8+
})
9+
export class AppComponent {
10+
buildMode = document['aot'] ? 'AOT' : 'JIT';
11+
}
12+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// #docregion
2+
import { NgModule } from '@angular/core';
3+
import { BrowserModule } from '@angular/platform-browser';
4+
5+
import { AppComponent } from './app.component';
6+
import { BaseComponent } from './base.component';
7+
import { SubComponent } from './sub.component';
8+
9+
@NgModule({
10+
imports: [ BrowserModule ],
11+
declarations: [
12+
AppComponent,
13+
BaseComponent,
14+
SubComponent
15+
],
16+
bootstrap: [ AppComponent ]
17+
})
18+
export class AppModule { }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#speak { font-style: italic; color: blue; }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component, Input, Injectable } from '@angular/core';
2+
3+
@Injectable()
4+
export class ServiceA {
5+
name = 'Service A';
6+
}
7+
8+
@Injectable()
9+
export class ServiceB {
10+
name = 'Service B';
11+
}
12+
13+
export const BASE_PROVIDERS = [ ServiceA, ServiceB ];
14+
15+
export const BASE_METADATA = {
16+
moduleId: module.id,
17+
selector: 'base-comp',
18+
template: `
19+
<h3>{{speaker}} sez:</h3>
20+
<p id="speak">I am the base component. Koo-koo-ka-choo.</p>
21+
<p>{{services}}</p>
22+
`,
23+
styleUrls: [ './base.component.css'] ,
24+
providers: [BASE_PROVIDERS]
25+
};
26+
27+
@Component(BASE_METADATA)
28+
export class BaseComponent {
29+
@Input() speaker: string;
30+
services: string;
31+
32+
constructor(private a: ServiceA, private b: ServiceB) {
33+
this.services = `ServiceA is ${a.name}; Service B is ${b.name}`;
34+
}
35+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// #docregion
2+
import { platformBrowser } from '@angular/platform-browser';
3+
import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory';
4+
5+
console.log('Running AOT version');
6+
document['aot'] = true;
7+
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// #docregion
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import { AppModule } from './app.module';
4+
5+
console.log('Running JIT version');
6+
document['aot'] = false;
7+
platformBrowserDynamic().bootstrapModule(AppModule);

0 commit comments

Comments
 (0)