Я создал Directive
в Angular7, но когда мне нужно использовать, он показывает мне эту ошибку:
Ошибка: StaticInjectorError (AppModule) [NgForOf -> TemplateRef]:
StaticInjectorError (Платформа: ядро) [NgForOf -> TemplateRef]:
NullInjectorError: Нет поставщика для TemplateRef!
Ошибка: StaticInjectorError (AppModule) [NgForOf -> TemplateRef]:
StaticInjectorError (Платформа: ядро) [NgForOf -> TemplateRef]:
Я создаю эту директиву в SharedModule
:
@NgModule({
declarations: [FilderrorComponent, UploadfileComponent, ImageComponent, ValidatePermissionDirective],
imports: [
CommonModule
],
exports: [ FilderrorComponent, UploadfileComponent, ImageComponent, ValidatePermissionDirective]
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [ FilderrorComponent, UploadfileComponent, ImageComponent , ValidatePermissionDirective]
};
}
}
и это моя директива:
@Directive({
selector: '[appValidatePermission]'
})
export class ValidatePermissionDirective implements OnInit {
show: boolean;
constructor(private templateRef: TemplateRef<any>,
private viewContainerRef: ViewContainerRef
, private dynamic: DynamicPermissionService) { }
// tslint:disable-next-line:no-input-rename
@Input() AccessName: string;
ngOnInit() {
this.ValidatePemission();
if (this.show) {
this.viewContainerRef.createEmbeddedView(this.templateRef);
} else {
this.viewContainerRef.clear();
}
}
ValidatePemission() {
console.log('AccessName : ', this.AccessName);
const find = this.dynamic.dynamicModel.find(x =>
!! x.actionsVM.find(z => z.actionEnglishName === this.AccessName));
console.log(find);
if (find) {
console.log(true);
this.show = true;
} else {
console.log(false);
this.show = false;
}
}
}
и я определяю shareModule
в AdminModule :
@NgModule({
declarations: [],
imports: [
SharedModule,
AdminpanelRoutingModule,
],
providers: [Toolkit, { provide: HTTP_INTERCEPTORS, useClass: RequestInterceptor, multi: true }]
})
export class AdminpanelModule { }
и я использую Directive
в HTML:
<span [appValidatePermission]="CreateRole">
<router-outlet></router-outlet>
</span>
В чем проблема ??? Как я могу решить это?