angular-docs-cn/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts

24 lines
548 B
TypeScript

import { Component, Inject, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
// #docregion
@Component({
selector: 'hero-di-inject',
template: `<h1>Hero: {{name}}</h1>`
})
class HeroComponent {
constructor(
@Inject('heroName')
private name: string) {
}
}
// #enddocregion
@NgModule({
imports: [ BrowserModule ],
providers: [ { provide: 'heroName', useValue: 'Windstorm' } ],
declarations: [ HeroComponent ],
bootstrap: [ HeroComponent ]
})
export class HeroesDIInjectModule { }