angular - Angular 11.0.3 无法绑定到 DIRECTIVE,因为它不是元素的已知属性
问题描述
我通过 Angular CLI 生成了新的 @Directive,它被导入到我的 app.module.ts 中:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
import { DatosEnMemoriaService } from './datos-en-memoria.service';
import { ClonarDirective } from './investigaciones/marta/clonar.directive';
@NgModule({
declarations: [
AppComponent,
ClonarDirective,
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
InMemoryWebApiModule.forRoot(DatosEnMemoriaService, {
passThruUnknownUrl: true, post204: false, put204: false
})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我尝试在 mycomponent.html 中使用
<li *appClonar="3">
<button (click)="this.router.navigateByUrl('/gesprodes');" >
Gesprodes
<span>Inicia a aplicación de gesprodes</span>
</button>
</li>
指令.ts:
import { Directive,Input,TemplateRef,ViewContainerRef } from '@angular/core';
@Directive({
selector: '[appClonar]'
})
export class ClonarDirective {
constructor(private tp:TemplateRef<any>,
private vcr:ViewContainerRef) { }
@Input() appClonar:number;
ngOnInit(): void {
this.vcr.createEmbeddedView(this.tp);
console.log(this.appClonar);
for(let i = 0; i<this.appClonar ;i++){
this.vcr.createEmbeddedView(this.tp);
}
}
}
我得到了错误:
core.js:9813 NG0303:无法绑定到“appClonar”,因为它不是“li”的已知属性。
我尝试了几乎所有可能的更改,按照这个角度文档,一切都应该工作,但它没有。
我的版本角度:11.0.3 我的版本节点:12.0.0
任何帮助
解决方案
你试过这个
<li [appClonar] >
</li>
推荐阅读
- html - 如何在 RMarkdown 中将浮动图像(环绕文本)与居中标题对齐?
- reactjs - 无法将反应手风琴面板项目传递给操作调用
- java - Gui- 使对象按特定标准移动
- swift - Swift 4 如何将文本打印到标签
- python - 为什么 numpy 混合基本/高级索引取决于切片邻接?
- java - 在另一个线程中捕获库引发的异常(android)
- php - 如何在 Wordpress 中为自定义表格创建单个视图页面
- python - 通过 Django 网页执行循环 python 脚本
- qfiledialog - 无法使用 QFileDialog.getSaveFileName 保存为 csv
- python - pytorch 中的自适应池化如何工作?