I've a project (that was working a few days ago) that uses angular 9 without Ivy
tsconfig
{
"angularCompilerOptions": {
"enableIvy": false,
},
"compilerOptions": {
"downlevelIteration": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "Node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2018",
"dom"
],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "dist",
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
}
My directive
export class SomeDirective {
constructor(viewContainerRef: ViewContainerRef) {
this.workspace = (viewContainerRef as any)._view.component;
}
}
For some reason (probably on classpath), I got and error when I try to get the viewContainerRef._view.
TypeError: Cannot read property 'component' of undefined
at new SomeDirectiveDirective (someDirective.directive.ts:18)
at NodeInjectorFactory.SomeDirectiveDirective_Factory [as factory] (ɵfac.js? [sm]:1)
at getNodeInjectable (core.js:5993)
at instantiateAllDirectives (core.js:12997)
at createDirectivesInstances (core.js:12209)
at ɵɵelementStart (core.js:21302)
at WorkspaceComponent_Template (template.html:1)
at executeTemplate (core.js:12169)
When I debug it I see that viewContainerRef doesn't contain _view but instead _hostView.
Where the values _view and _hostView comes from? It's related with the Ivy compiler? If so, it means that my "angularCompilerOptions" is being ignored, right?
ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.1.15
Node: 12.3.1
OS: win32 x64
Angular: 9.1.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Ivy Workspace: No
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.15
@angular-devkit/build-angular 0.901.15
@angular-devkit/build-optimizer 0.901.15
@angular-devkit/core 9.1.15
@angular-devkit/schematics 9.1.15
@angular/cdk 9.2.4
@angular/cli 9.1.15
@angular/material 9.2.4
@ngtools/webpack 9.1.15
@schematics/angular 9.1.15
@schematics/update 0.901.15
rxjs 6.6.7
typescript 3.8.3
webpack 4.46.0
PS- Is this information enough? Edit - Added the compiler options