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

Commit ed99894

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

16 files changed

+242
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
## Building it
10+
11+
```
12+
# compile with AOT, then rollup. Noisy.
13+
npm run build:aot
14+
15+
# start server and JIT/TS watching as usual
16+
npm start
17+
```
18+
The browser displays the AOT version (`index.html`) by default.
19+
You can tell by looking at the browser tab (it says "AOT:...") and in the console.
20+
21+
To see the JIT version, put `index-jit.html` in the address bar.
22+
You can tell by looking at the browser tab (it says "JIT:...") and in the console.
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</h1>
3+
<base-comp speaker="Paul"></base-comp>
4+
<sub-comp speaker="Helen"></sub-comp>
5+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
@Component({
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+
export class BaseComponent {
27+
@Input() speaker: string;
28+
services: string;
29+
30+
constructor(private a: ServiceA, private b: ServiceB) {
31+
this.services = `ServiceA is ${a.name}; Service B is ${b.name}`;
32+
}
33+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// #docregion
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import { AppModule } from './app.module';
4+
5+
console.log('Running JIT version');
6+
platformBrowserDynamic().bootstrapModule(AppModule);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);

0 commit comments

Comments
 (0)