'Injector is returning null using injector.get()
- I'm facing an issue with the
injector.get(ViewContainerRef)to get the instance ofViewContainerRef. It is returning null/undefined
when try to get the instance ofViewContainerRef. - It is available before i reach to the class to get the instance of
ViewContainerRef. The injector argument is being passed from child to parent using constructor arguments and trying to get the instance usinginjector.get(). That is returning null all the time. - Please help me to come out of this situation,Thanks.
export abstract class ChildClass extends ParentClass {
constructor(injector: Injector) {
super(injector);
}
}
export abstract class ParentClass{
public viewContainerRef:ViewContainerRef;
constructor(injector: Injector) {
this.viewContainerRef = injector.get(ViewContainerRef) **Here it is returning null.**
}
}
Solution 1:[1]
I'd struggled the same issue, finally identified that injector.get(ViewContainerRef) returns null when Ivy is disabled. (If Ivy is enabled, then injector correctly resolves it).
Seems ViewContainerRef should be specified as a param of the constructor in ViewEngine environment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sejin Park |
