在Angular 7中,您可以使用一个状态变量来控制确认弹出框的显示和隐藏。当用户点击取消时,您可以将状态变量设置为true,以保持组件在确认弹出框中持续存在。
以下是一个示例代码:
在组件的HTML模板中,您可以使用*ngIf指令根据状态变量来控制确认弹出框的显示和隐藏:
确认弹出框
您确定要取消吗?
在组件的Typescript代码中,您需要定义一个名为showConfirmation的状态变量,并在取消按钮的点击事件中将其设置为true:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
template: `
确认弹出框
您确定要取消吗?
`
})
export class ExampleComponent {
showConfirmation: boolean = true;
cancel() {
this.showConfirmation = false;
}
}
这样,当用户点击取消按钮时,确认弹出框将被隐藏,但组件仍然存在于DOM中,可以保持持续存在。