Angular Can';无法绑定到指令,因为它是';t元素角AOT的已知属性
我一直试图无济于事地解决我的问题 .html:Angular Can';无法绑定到指令,因为它是';t元素角AOT的已知属性,angular,angular2-directives,angular2-aot,Angular,Angular2 Directives,Angular2 Aot,我一直试图无济于事地解决我的问题 .html: <li [myHighlight]="color" defaultColor="violet" routerLinkActive="active"><a [routerLink]="['user']">Users <span class="sr-only" >(current)</span></a></li> app.module: import { PermissionsD
<li [myHighlight]="color" defaultColor="violet" routerLinkActive="active"><a [routerLink]="['user']">Users <span class="sr-only" >(current)</span></a></li>
app.module:
import { PermissionsDirective, HighlightDirective } from "./shared/directives/permisions.directive";
@NgModule({
imports: [
..
],
declarations: [
..
HighlightDirective,
..
],
bootstrap: [
ApplicationComponent,
],
providers: [
..
]
})
export class AppModule { }
我得到的错误:
Can't bind to 'myHighlight' since it isn't a known property of 'li'.
我正在使用具有以下设置的AOT编译器:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
]
},
"files": [
.. all the good stuff ..
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
},
"compileOnSave": true,
"buildOnSave": true
}
我的猜测是,由于AOT编译器,我应该以不同于指南中的方式定义指令。
这是我用过的指南。我还看了一个关于这方面的pluralsight课程,但对其他人来说,一切似乎都很顺利。有人能给我指出正确的方向吗?如果不是我找了几个小时我就不会在这里了
编辑:为什么它认为“myHighlight”是“li”的属性,而“RouterLink Active”是(我希望是)路由器指令的属性?问题是我在主application.module中“声明”了指令,而不是使用它的指令。我仍然不明白为什么每个模块必须声明它将使用的自己的指令,而不是在主模块中声明一次。我刚刚注意到,从app.module生成的ngFactory不包含我指令的导入。我将进一步研究。将指令不仅添加到声明中,还添加到主模块中的导出中
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
]
},
"files": [
.. all the good stuff ..
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
},
"compileOnSave": true,
"buildOnSave": true
}