I'm trying to initialize plugin in parent element through service and then use plugin object in child components. But i have problem that plugin object returns undefined in child components. I believe if i initialize plugin in constructor() then i could access it from child components, but i don't know how to do that.
Parent component
export class HomeComponent implements AfterViewInit {
constructor(private tooltip: TooltipService) { }
ngAfterViewInit(): void {
this.tooltip.initPlugin('.item-tooltip');
}
}
TooltipService code
@Injectable({
providedIn: 'root'
})
export class TooltipService {
public plugin: any;
constructor() {}
public initPlugin(elementId: string): void {
this.plugin = new pluginName(elementId);
}
}
Child component
export class AccordionComponent implements OnInit {
constructor(private tooltip: TooltipService) { }
ngOnInit(): void {
console.log(this.tooltip.plugin.class);
}
}