Angular 角度9(没有常春藤)如何从ViewContainerRef获取_视图?
我有一个项目(几天前还在工作),它使用angular 9而不使用常春藤 tsconfigAngular 角度9(没有常春藤)如何从ViewContainerRef获取_视图?,angular,angular9,angular-ivy,Angular,Angular9,Angular Ivy,我有一个项目(几天前还在工作),它使用angular 9而不使用常春藤 tsconfig { "angularCompilerOptions": { "enableIvy": false, }, "compilerOptions": { "downlevelIteration": true, "target": "es201
{
"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"
]
},
}
我的指令
export class SomeDirective {
constructor(viewContainerRef: ViewContainerRef) {
this.workspace = (viewContainerRef as any)._view.component;
}
}
由于某种原因(可能是在类路径上),我在尝试获取viewContainerRef.\u视图时遇到了错误
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)
调试它时,我看到viewContainerRef不包含_view,而是包含_hostView
值_view和_hostView来自哪里?
它和常春藤编译器有关?如果是这样,这意味着我的“angularCompilerOptions”被忽略了,对吗
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-这些信息足够吗?
编辑-添加了编译器选项