2016-01-11 07:49:12 -05:00
|
|
|
// #docplaster
|
2016-06-03 14:16:46 -04:00
|
|
|
// #docregion
|
2016-05-03 08:06:32 -04:00
|
|
|
import { Component, Injector } from '@angular/core';
|
2016-01-11 07:49:12 -05:00
|
|
|
|
2016-05-03 08:06:32 -04:00
|
|
|
import { Car, Engine, Tires } from './car/car';
|
2016-06-03 14:16:46 -04:00
|
|
|
import { Hero } from './heroes/hero';
|
2016-05-03 08:06:32 -04:00
|
|
|
import { HeroService } from './heroes/hero.service';
|
|
|
|
import { heroServiceProvider } from './heroes/hero.service.provider';
|
|
|
|
import { Logger } from './logger.service';
|
2016-01-11 07:49:12 -05:00
|
|
|
|
2016-06-03 14:16:46 -04:00
|
|
|
// #docregion injector
|
2016-01-11 07:49:12 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'my-injectors',
|
|
|
|
template: `
|
|
|
|
<h2>Other Injections</h2>
|
2016-03-04 01:50:42 -05:00
|
|
|
<div id="car">{{car.drive()}}</div>
|
2016-01-11 07:49:12 -05:00
|
|
|
<div id="hero">{{hero.name}}</div>
|
|
|
|
<div id="rodent">{{rodent}}</div>
|
|
|
|
`,
|
2016-06-03 14:16:46 -04:00
|
|
|
providers: [Car, Engine, Tires, heroServiceProvider, Logger]
|
2016-01-11 07:49:12 -05:00
|
|
|
})
|
|
|
|
export class InjectorComponent {
|
2016-06-03 14:16:46 -04:00
|
|
|
car: Car = this.injector.get(Car);
|
2016-01-11 07:49:12 -05:00
|
|
|
|
2016-06-03 14:16:46 -04:00
|
|
|
// #docregion get-hero-service
|
|
|
|
heroService: HeroService = this.injector.get(HeroService);
|
|
|
|
// #enddocregion get-hero-service
|
|
|
|
hero: Hero = this.heroService.getHeroes()[0];
|
2016-01-11 07:49:12 -05:00
|
|
|
|
2016-06-07 19:06:25 -04:00
|
|
|
constructor(private injector: Injector) { }
|
|
|
|
|
2016-01-11 07:49:12 -05:00
|
|
|
get rodent() {
|
2016-06-07 19:06:25 -04:00
|
|
|
let rousDontExist = `R.O.U.S.'s? I don't think they exist!`;
|
2016-06-03 14:16:46 -04:00
|
|
|
return this.injector.get(ROUS, rousDontExist);
|
2016-01-11 07:49:12 -05:00
|
|
|
}
|
|
|
|
}
|
2016-06-03 14:16:46 -04:00
|
|
|
// #enddocregion injector
|
2016-01-11 07:49:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* R.O.U.S. - Rodents Of Unusual Size
|
|
|
|
* // https://www.youtube.com/watch?v=BOv5ZjAOpC8
|
|
|
|
*/
|
|
|
|
class ROUS { }
|