注入可能な CameraChannelService を ngModule のプロバイダー配列に追加すると:
import { CameraChannelService } from './camera-channel.service';
@NgModule({
declarations: [
AppComponent,
BabylonWallpaperDirective,
MenuComponent,
WorksComponent,
LabsComponent,
ProfileComponent,
ActionBtnComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
providers: [
CameraChannelService
],
bootstrap: [AppComponent]
})
そのコンポーネントだけの新しいインスタンスを作成しますか? NgModules 宣言コンポーネントの 1 つに挿入すると?
import { Component, OnInit } from '@angular/core';
import {CameraChannelService} from '../camera-channel.service';
@Component({
selector: 'app-works',
templateUrl: './works.component.html',
styleUrls: ['./works.component.scss'],
providers: [CameraChannelService]
})
export class WorksComponent implements OnInit {
constructor(private cameraChannel: CameraChannelService) { }
ngOnInit() {
console.log(this.cameraChannel);
}
}