错误:StaticInjectorError(AppModule)[NgForOf-> TemplateRef]

时间:2019-06-09 11:01:09

标签: javascript angular typescript angularjs-directive angular7

我需要为用户创建Directive来验证显示按钮。

我在SahreMudole中创建指令:

    @Directive({
  selector: '[appValidatePermission]'
})
export class ValidatePermissionDirective implements OnInit {

  constructor(private templateRef: TemplateRef<any>,
              private viewContainerRef: ViewContainerRef
    ,         private dynamic: DynamicPermissionService) { }

  // tslint:disable-next-line:no-input-rename
  @Input('AccessName') AccessName: string;

  ngOnInit() {
    this.ValidateAccessPemission(this.AccessName);
  }
  ValidateAccessPemission(item: string) {
    if (this.FindAceess(item)) {
      console.log('in d true');
      this.viewContainerRef.createEmbeddedView(this.templateRef);
    } else {
      console.log(' in dfalse');
      this.viewContainerRef.clear();
    }
  }

  FindAceess(acess: string): boolean {
    const find = this.dynamic.dynamicModel.filter(x =>
      x.actionsVM.filter(z => z.actionEnglishName === acess));
    if (find == null) {
        return false;
      } else {
        return true;
      }
  }
}

和shareMudole中:

   @NgModule({
  declarations: [ValidatePermissionDirective],
  imports: [
    CommonModule
  ],
  exports: [ValidatePermissionDirective]
})
export class SharedModule {

    static forRoot(): ModuleWithProviders {
      return {
        ngModule: SharedModule,
        providers: [ValidatePermissionDirective]
      };
  }
}

我在AdminPanme.Module中使用shareModule:

imports: [
SharedModule,

]

我用html代码来称呼它:

  <span appValidatePermission [AccessName]='GetRoleList'>
    <router-outlet></router-outlet>
  </span>

但是它告诉我这个错误:

  

错误:StaticInjectorError(AppModule)[NgForOf-> TemplateRef]

出什么问题了?我该如何解决这个问题?

0 个答案:

没有答案