在angular2有可能在一個@Component元素定義提供商等在@Component和@Module中注入提供者之間Angular2有什麼區別?
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers : [ DataService ]
})
export class HomeComponent implements OnInit {
...
}
以及在一個
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [ DataService ],
bootstrap: [AppComponent ]
})
export class AppModule { }
是什麼在@NgModule或在限定的提供者之間的差@零件?如果我應該選擇其中之一,那麼應該怎樣更好地定義供應商?