[英]Template parse errors angular 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个。未提供“ opts”的参数。
我已经添加了我的app.module.ts:
import { MyDialogComponent } from './pages/interfacage/test/test.component';
那么我该如何解决这个问题。
我正在使用此tuto 路径
从Angular 8开始,您需要在ViewChild中添加{ static: true }
尝试:
@ViewChild('TemplateRef', { static: true }) TemplateRef: any;
现在可以在Angular8中使用
@ViewChild(TemplateRef, {static: false})
private templateRef: TemplateRef<any>;
https://stackblitz.com/edit/angular-material2-issue-yqcfpj?file=app/app.component.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.