Witam,
Mam pytanie odnosnie InjectionToken:
export const EVENT_ACTIONS_DATA = new InjectionToken<Event>('tech.event.actions');
// jakis tam komponent i jego metoda
getComponentInjector(e: Event): any {
return ReflectiveInjector.resolveAndCreate([{ provide: EVENT_ACTIONS_DATA, useValue: e }], this._injector);
}
// potem komponent ktory chce sobie pobrac EVENT_ACTIONS_DATA w kontruktorze
export class TechNotificationsGoogleActionsComponent implements OnInit {
public notification: Event;
constructor(
private _injector: Injector,
// @Inject(EVENT_ACTIONS_DATA) public notification: Event
) { }
ngOnInit(): void {
this.notification = this._injector.get(EVENT_ACTIONS_DATA);
}
}
Komponent inicjalizuje za pomoca:
<ng-container *ngComponentOutlet="getComponent(e); injector: getComponentInjector(e)"></ng-container>
O ile wstrzykiwanie Injectora i pobieranie EVENTS_ACTIONS_DATA za pomoca this._injector.get(EVENT_ACTIONS_DATA) dziala to juz jesli uzyje @Inject(EVENT_ACTIONS_DATA) public notification: Event nie potrafi.
Sorry ale to tak napisane na szybko