javascript - 模板解析错误角度 8
问题描述
我正在使用角度 8 我想显示一个带有角度材料的弹出窗口,这就是我所做的:
在我的 HTML 中:
<button (click)="myDia.open()">Open it</button>
Result: {{result | json}}
<my-dialog (result)="result = $event" #myDia>
<h1 mat-dialog-title>Dialog Title</h1>
<mat-dialog-content>
Content
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="myDia.close()">Cancel</button>
<button mat-button (click)="myDia.close({foo:'bar'})">Confirm</button>
</mat-dialog-actions>
</my-dialog>
这是 Ts 文件:
@Component({
selector: 'my-dialog',
template: `
<ng-template>
<ng-content></ng-content>
</ng-template>
`
})
export class MyDialogComponent {
@ViewChild(TemplateRef)
private templateRef: TemplateRef<any>;
@Output()
result = new EventEmitter<boolean>();
private dialogRef: MatDialogRef<any>;
constructor(private dialog: MatDialog) {}
open() {
this.dialogRef = this.dialog.open(this.templateRef);
this.dialogRef.afterClosed().subscribe(val => {
this.result.emit(val);
});
}
close(val: any) {
this.dialogRef.close(val);
}
}
我在这一行有一个问题:
@ViewChild(TemplateRef)
错误是:
预期有 2 个参数,但得到 1 未提供“选择”的参数。
我在我的 app.module.ts 中添加了:
import { MyDialogComponent } from './pages/interfacage/test/test.component';
那么我该如何解决这个问题。
我正在使用这个 tuto路径
解决方案
现在它在Angular8中工作
@ViewChild(TemplateRef, {static: false})
private templateRef: TemplateRef<any>;
https://stackblitz.com/edit/angular-material2-issue-yqcfpj?file=app/app.component.html
推荐阅读
- html - 如何在键值对中获得确定的值?
- javascript - jQuery中不推荐使用“事件”是什么意思?
- windows - 具有可变子字符串长度的 Windows Batch SET?
- python - 使用join()后如何在执行过程中终止进程?
- javascript - 启动类型错误:无法读取未定义的属性“集合”
- django - Django:关系“APIs_api”的“category_id”列中的空值违反非空约束
- javascript - 如果可以在字符串上找到属性名称,为什么在 undefined 上找不到呢?
- javascript - 如何正确地将数据从 vue 组件发布到 laravel 控制器
- download - 下载 adobe 包
- machine-learning - 是否有一种既定的方法来实现基于梯度的修剪 w 神经网络?