I would like to to pass an array of data (data from the URL) from ParentComponent to ChildDirective with a sharedDataService. I usedthis but i don't know if it's the best way to do it.
Here is my ParentComponent
@Component({
...
directives: [ChildDirective, ROUTER_DIRECTIVES],
})
export class FormsAddClient implements OnInit{
params=[];
constructor(
private _routeParams: RouteParams,
private _sharedData: SharedData){
this.params['video_id']=this._routeParams.get('video_id');
this.params['soc_id']=this._routeParams.get('soc_id');
}
ngOnInit(): void {
this._sharedData.videoData.next(this.params);
}
}
My ChildDirective
export class ChildDirective {
videoData;
constructor(
private _sharedData:SharedData) {
this._sharedData.videoData.subscribe(data=>{
this.videoData = data;
console.log(this.videoData;
});
}
}
And my ShareDataService
import {Injectable,Inject} from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class SharedData {
videoData = new Subject();
}
Any ideas ?