Angular2-modal确认回调

时间:2017-01-18 04:45:59

标签: javascript angular modal-dialog bootstrap-modal

我在Angular 2项目中编程。我有几个组件,我想使用相同的对话确认框。因此我将确认代码放在一个单独的类中。对话框应该检查用户是想继续还是保存数据。

我正在使用Angular2-modal来实现这个目的。

当按下确认中的任一按钮时,我希望能够将此答案返回到调用此确认的组件,以便我可以在那里执行某些操作。

我的代码如下所示:

这是我从我的组件中调用的函数:

this._popup.confirmSaveTemp(this.modal);

这是带有确认码的功能。目前我可以在我放置的两个地方打印出OK或取消" TODO"。

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
        } );
    });
  }

*问题:如何通知父母&#34;组件对话的响应是什么或如何从&#34;父母&#34;零件? *

1 个答案:

答案 0 :(得分:0)

您可以从父类传递函数作为这样的参数:

<tr>
    <td>
        <img src="2.jpg" alt="" title="" style="width:40px; height:40px;margin-top: -23px; margin-left: -6px;">
    </td>
    <td width="85%" valign="bottom">
        <font size="4" face="Arial"><b>Happy to help</b></font>
        <hr class="styleHr">
    </td>
</tr>

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) ); }

confirmSaveTemp
相关问题