forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcar.components.ts
74 lines (67 loc) · 1.73 KB
/
car.components.ts
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
70
71
72
73
74
import { Component } from '@angular/core';
import {
CarService, CarService2, CarService3,
EngineService, EngineService2, TiresService
} from './car.services';
////////// CCarComponent ////////////
@Component({
selector: 'c-car',
template: `<div>C: {{description}}</div>`,
providers: [
{ provide: CarService, useClass: CarService3 }
]
})
export class CCarComponent {
description: string;
constructor(carService: CarService) {
this.description = `${carService.getCar().description} (${carService.name})`;
}
}
////////// BCarComponent ////////////
@Component({
selector: 'b-car',
template: `
<div>B: {{description}}</div>
<c-car></c-car>
`,
providers: [
{ provide: CarService, useClass: CarService2 },
{ provide: EngineService, useClass: EngineService2 }
]
})
export class BCarComponent {
description: string;
constructor(carService: CarService) {
this.description = `${carService.getCar().description} (${carService.name})`;
}
}
////////// ACarComponent ////////////
@Component({
selector: 'a-car',
template: `
<div>A: {{description}}</div>
<b-car></b-car>`
})
export class ACarComponent {
description: string;
constructor(carService: CarService) {
this.description = `${carService.getCar().description} (${carService.name})`;
}
}
////////// CarsComponent ////////////
@Component({
selector: 'my-cars',
template: `
<h3>Cars</h3>
<a-car></a-car>`
})
export class CarsComponent { }
////////////////
export const carComponents = [
CarsComponent,
ACarComponent, BCarComponent, CCarComponent
];
// generic car-related services
export const carServices = [
CarService, EngineService, TiresService
];