This repository was archived by the owner on Dec 4, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 862
Expand file tree
/
Copy pathsub.component.ts
More file actions
69 lines (56 loc) · 1.68 KB
/
sub.component.ts
File metadata and controls
69 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Component, Injectable } from '@angular/core';
import { BaseComponent, BASE_METADATA, BASE_PROVIDERS, ServiceA } from './base.component';
///////// SubComponent service substitution ////
@Injectable()
export class ServiceASub {
name = 'A-sub';
}
///////// SubComponent Metadata Trials ////
// The intended, fully specified SubComponent metadat. We know this works
const subMeta = {
moduleId: module.id,
selector: 'sub-comp',
template: `
<h3>{{speaker}} sez:</h3>
<p id="speak">I am the SUB component. Hear me roar.</p>
<p>{{services}}</p>
`,
styleUrls: [ './base.component.css'] ,
providers: [
BASE_PROVIDERS,
{provide: ServiceA, useClass: ServiceASub}
]
};
////////////////////
// This works in JIT but not AOT
export function blendMetadata() {
return Object.assign({}, BASE_METADATA, subMeta);
}
//////////////////////////
// Manual inheritance
const inheritMetadata = {
// inherit (silly)
moduleId: BASE_METADATA.moduleId,
// Override
selector: 'sub-comp',
template: `
<h3>{{speaker}} sez:</h3>
<p id="speak">I am the SUB component. Hear me roar.</p>
<p>{{services}}</p>
`,
// Extend providers (actually overrides)
providers: [
BASE_METADATA.providers, // inherit
{provide: ServiceA, useClass: ServiceASub}
],
// Inherit
styleUrls: BASE_METADATA.styleUrls // inherit
};
////////////// SubComponent ////////////////////////
// This works in JIT and AOT
// @Component(subMeta)
// This works in JIT but not AOT
// @Component(blendMetadata())
// This works in JIT and AOT
@Component(inheritMetadata)
export class SubComponent extends BaseComponent { }