【发布时间】:2021-06-16 10:49:39
【问题描述】:
我在 Angular 项目中有一个父组件和一个子组件,我需要从子打开一个放置在父组件中的模态,所以我使用 ng-Zorro,如果我有类似的代码用于打开父组件中的modal:
家长: 从'@angular/core'导入{组件};
@Component({
selector: 'nz-demo-modal-basic',
template: `
<button nz-button [nzType]="'primary'" (click)="showModal()"><span>Show Modal</span></button>
<nz-modal [(nzVisible)]="isVisible" nzTitle="The first Modal" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
<ng-container *nzModalContent>
<p>Content one</p>
<p>Content two</p>
<p>Content three</p>
</ng-container>
</nz-modal>
`
})
export class NzDemoModalBasicComponent {
isVisible = false;
constructor() {}
showModal(): void {
this.isVisible = true;
}
handleOk(): void {
console.log('Button ok clicked!');
this.isVisible = false;
}
handleCancel(): void {
console.log('Button cancel clicked!');
this.isVisible = false;
}
}
我应该怎么做才能从孩子打开相同的模式? 是相关的@Input 和@Output 吗? 我也想知道它,因为我不想在 de 项目中有重复的代码,所以服务也可以对它有用吗?
【问题讨论】:
标签: angular