Javascript 当模式打开时,如何在angular2 ngx引导模式中实例化
这是我的父组件模板片段:Javascript 当模式打开时,如何在angular2 ngx引导模式中实例化,javascript,angular,typescript,frontend,ngx-bootstrap,Javascript,Angular,Typescript,Frontend,Ngx Bootstrap,这是我的父组件模板片段: <button type="button" (click)="addModal.show();">Add</button> <add-modal #addModal></add-modal> 添加 这是我的模态组件: Component({ selector: 'card-add-modal', template: ` <div *ngIf="isShowModal" bsModa
<button type="button" (click)="addModal.show();">Add</button>
<add-modal #addModal></add-modal>
添加
这是我的模态组件:
Component({
selector: 'card-add-modal',
template: `
<div *ngIf="isShowModal" bsModal #addModal="bs-modal" [config]="{show: true, backdrop: 'static'}" (onHidden)="onHidden()" class="modal fade">
<!-- header... -->
<div class="modal-body">
<input type="text" name="name" id="name" [(ngModel)]="model.test">
</div>
<!-- footer... -->
</div>
`
})
export class ModalComponent{
@ViewChild('addModal') public addModal: ModalDirective;
isShowModal: boolean = true;
model: any = { test: 'hey modal...' };
show(){ this.isShowModal = true; }
hide(){ this.addModal.hide(); }
onHidden(){ this.isShowModal = false; }
}
组件({
选择器:“卡添加模式”,
模板:`
`
})
导出类ModalComponent{
@ViewChild('addModal')公共addModal:ModalDirective;
isShowModal:布尔值=真;
模型:any={test:'hey modal…'};
show(){this.isshowmodel=true;}
hide(){this.addModal.hide();}
onHidden(){this.isshowmodel=false;}
}
好了,现在一切正常
但是在我点击Add
按钮,Modal
show之后,我在输入框中键入了一些内容,然后关闭并重新打开,这些输入的内容仍然存在
我发现这实际上是在页面上,模态已经被实例化完成了,在这里显示和隐藏只是添加删除DOM,模态组件不会被破坏
但是,我希望每次单击“添加”重新创建模态实例时,在销毁当前模态后,我都没有找到这种方法。关闭模态时是否清除其内容?