小编Par*_*iya的帖子

无法绑定到 Directive('appHasAccess'),因为它不是“input”的已知属性

我创建了一个自定义属性指令库包并将其安装到 myProject 中,当我尝试使用此自定义指令时会引发错误。

错误错误:未捕获(承诺):错误:模板解析错误:无法绑定到“appHasAccess”,因为它不是“输入”的已知属性。

我使用的代码如下:

所有可能的尝试我都做了。任何人都知道我如何解决这个问题。

1.指令:HasAccessDirective.ts

@Directive({
  selector: '[appHasAccess]',
})

export class HasAccessDirective {

accessDetail = { 'a': 1 }
 @Input('appHasAccess') set appHasAccess(accessDetail: any) {
    // Based on right control enable/disable
    this.eleRef.nativeElement.disabled = this.appRights.hasRights(accessDetail);
}
constructor(private eleRef: ElementRef,
    private appRights: MyService) { }
}
Run Code Online (Sandbox Code Playgroud)

2.模块:DigiUserRightsModule.ts

   @NgModule({
        declarations: [
            HasAccessDirective
        ],
        imports: [
            CommonModule,
            HttpClientModule,
        ],
        exports: [
            HasAccessDirective
        ],
        providers: [UserRightsService]
    })

export class DigiUserRightsModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: DigiUserRightsModule,
            providers: [UserRightsService]
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

angularjs-directive angular angular-library angular5

5
推荐指数
1
解决办法
6054
查看次数