【发布时间】:2020-07-11 22:04:58
【问题描述】:
您好,我有一种带有输入的确认模式:
@Input('input1') input1: string;
@Input('input2') input2: boolean;
constructor(private changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit() {
}
public openModal(): void {
console.log(this.input2)
console.log(this.input1)
this.confirmationModal.nativeElement.classList.add('open-modal');
}
当我在订阅方法中打开此模式时的父组件。在这种方法中,我分配的值是这样的:
@ViewChild('confirmationModal') confirmationModal;
input1: string;
input2: boolean;
ngOnInit(): void {
}
ngOnDestroy(): void {
}
close(project: any) {
this.service.close(project).subscribe((success: ModelDto) => {
this.confirmationModal.openModal();
this.input2 = success.input2;
console.log(this.input2)
this.input1 = 'Some text';
});
}
在 html 中我有:
<app-confirmation-modal #confirmationModal
[input1]="input1"
(sendConfirm)="toggleSettled($event)"
(generateReport)="generateReport()"
[input2]="input2">
</app-confirmation-modal>
这是我的confirmationModal中的openModal方法:
console.logs 提供的两个仅在第一次打开模态时才给出 undefined。
因此,当我第一次尝试打开模式时,我得到了一个空模式,并且 input1 和 input2 未定义。但是从这一点开始,每次我打开一个模态时,我都会得到应该在模态和console.logs 中存在的值。所以问题只是第一次打开,我不知道是什么原因造成的。
编辑: 我已经对其进行了更多时间的测试,它似乎延迟了 1 次单击。我的意思是 Modal 中显示的值来自一个循环之前的值,而不是实际点击中的值
【问题讨论】:
标签: html angular modal-dialog frontend