在我的角度应用中 我正在使用ngx-bootstrap模态。
单击按钮后显示和隐藏模式(onShown
/ onHidden
)时,此模式用于返回可观察到的回调。
我的代码如下所示:
import {Injectable, TemplateRef} from '@angular/core';
import {BsModalService} from 'ngx-bootstrap/modal';
import {BsModalRef} from 'ngx-bootstrap/modal/bs-modal-ref.service';
@Injectable()
export class MyService {
modalRef: BsModalRef;
constructor(private modalService: BsModalService) {
}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template ,{ class: ' modal-lg' } );
}
onModalShown(){
return this.modalService.onShown;
// I WANT TO RETURN this.modalService.onShown + modalRef
onModalHidden(){
return this.modalService.onHidden;
}
}
我的目的是如何结合使用onModalShown
/onModalHidden
方法,以便可以modalRef
在this.modalService.onShown
响应的同时将引用附加到模态?
我想返回this.modalService.onShown + modalRef,并能够在我的组件中订阅它并获取两个数据
@Component()
export class MyComponent {
constructor( private myService : MyService) {}
whenCallbackFired(){
this.myService.onModalShown.subscribe(()=>{
GET HERE BOTH INFORMATIONS ??
})
}
}
要注意 ; modalRef
单击按钮后设置
建议?
这样就足够了:
onModalShown() {
return this.modalService.onShown.pipe(
map((directive) => ({ directive, modalRef: this.modalRef })
);
}
在组件内部,您可以执行以下操作:
whenCallbackFired(){
this.myService.onModalShown.subscribe(({ directive, modalRef })=> {
console.log(modalRef);
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句