[英]Angular2-modal confirm callback
I am programming in an Angular 2 project. 我正在编写一个Angular 2项目。 I have a several component where I want to use the same dialogue confirm box.
我有几个组件,我想使用相同的对话确认框。 Therefore i have put the confirm code in a separate class.
因此我将确认代码放在一个单独的类中。 The dialogue box is supposed to check whether a user wants to continue or save data.
对话框应该检查用户是想继续还是保存数据。
I am using Angular2-modal for this pupose. 我正在使用Angular2-modal来实现这个目的。
When either button on the confirm is pressed, I want to be able to return this answer to the component that called this confirm so I can perform certain actions there. 当按下确认中的任一按钮时,我希望能够将此答案返回到调用此确认的组件,以便我可以在那里执行某些操作。
My code looks like this: 我的代码看起来像这样:
This is the function I call from my component: 这是我从我的组件调用的函数:
this._popup.confirmSaveTemp(this.modal);
This is the function with the confirm code. 这是带有确认码的功能。 Currently I can print out OK or cancel in the two spots where I have placed "TODO".
目前我可以在我放置“TODO”的两个地方打印出OK或取消。
confirmSaveTemp(modal, target, param){
console.log(target);
modal.confirm()
.size('lg')
.isBlocking(true)
.showClose(false)
.keyboard(27)
.title('Warning')
.body(`
<p><b>Some fields have been <span class="text-danger">marked with red</span> because of one or several following reasons:</b></p>
<ul>
<li>You forgot to fill out all input fields</li>
<li>Entered values are unrealistically high or low</li>
<li>Use of illegal characters (e.g. typing letters instead of numbers for a persons age)</li>
</ul>
<p><b>Please make sure that you have filled out the form correctly.</b></p>
<p>
<b>If you are finished entering all values for this page and want to permanently save, click <span class="text-success">Continue</span>.</b>
<br>
<b>If you expect to enter the remaining values at another time click <span class="text-warning">Save Temporarily</span></b>
</p>
<p></p>
`)
.footerClass('defaultPopupFooter')
.okBtn('Continue')
.cancelBtn('Save Temporarily')
.okBtnClass('btn btn-success')
.cancelBtnClass('btn btn-warning')
.open()
.then( (resultPromise) => {
resultPromise.result.then( (result) => {
//TODO - CALL SAVE FUNCTION
},
() => {
//TODO - SAVE TEMP
} );
});
}
* Question: How can I inform the "parent" component what the response of this dialogue is OR how can call a function from the "parent" component? *问题:如何通知“父”组件该对话的响应是什么或如何从“父”组件调用函数? *
*
You can pass functions as parameters like this from the parent class: 您可以从父类传递函数作为这样的参数:
private okCallback() {
// do stuff on ok
}
private cancelCallback() {
// do stuff on cancel
}
openModal() {
// ...
this._popup.confirmSaveTemp(
this.modal,
target,
param,
this.okCallback.bind(this),
this.cancelCallback.bind(this)
);
}
And in the confirmSaveTemp
: 并在
confirmSaveTemp
:
confirmSaveTemp(modal, target, param, okCallback, cancelCallback){
console.log(target);
modal.confirm()
// ...
.open()
.then( (resultPromise) => {
resultPromise.result.then( (result) => {
//TODO - CALL SAVE FUNCTION
},
() => {
//TODO - SAVE TEMP
} );
})
// on OK click
.then(okCallback)
// on Cancel click
.catch(cancelCallback);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.