php*_*oid 1 javascript typescript ngx-bootstrap angular
我有一个场景,将数据保存到数据库后,我需要关闭Bs-modal弹出窗口,并且我的保存是在子组件中完成的,因此我Bs-modal使用 ()Input 在子组件中传递,并使用那里隐藏弹出窗口,但无法读取我的子组件中的模态
HTML 父组件
<div bsModal #lgModal2="bs-modal" class="modal fade" tabindex="-1"
role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title pull-left">Edit Product</h4>
<button type="button" class="close pull-right" (click)="lgModal2.hide()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<app-edit-product [productId]="prodId" [modalId]="lgmodal2" #child ></app-edit-product>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
子组件 TS
import { BsModalRef } from 'ngx-bootstrap';
export class EditProductComponent implements OnInit {
@Input() modalId:BsModalRef;
somefunction(){
this.modalId.hide();
}
}
Run Code Online (Sandbox Code Playgroud)
错误:发生意外错误!类型错误:无法读取未定义的属性“隐藏”
也尝试过
@Output() closeModal:EventEmitter<Event> = new EventEmitter();
@Input() onHide:any;
Run Code Online (Sandbox Code Playgroud)
然后
somefunction(){
this.closeModal.emit(this.onHide);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都会非常感谢!
HTML 父级:
<div bsModal #lgModal2="bs-modal" class="modal fade" tabindex="-1"
role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title pull-left">Edit Product</h4>
<button type="button" class="close pull-right" (click)="hideModal()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<app-edit-product [productId]="prodId" [modalId]="lgmodal2" (saveDone)="hideModal()" #child ></app-edit-product>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
子组件 TS:
export class EditProductComponent implements OnInit {
@Output() saveDone: EventEmitter<any> = new EventEmitter<any>();
somefunction(){
this.saveDone.emit();
}
}
Run Code Online (Sandbox Code Playgroud)
父组件 TS:
import { Component, ViewChild } from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap/modal';
export class ParentComponent implements OnInit {
@ViewChild('lgModal2') lgModal2: ModalDirective;
hideModal(){
this.lgModal2.hide();
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
7572 次 |
| 最近记录: |