【问题标题】:Why AlertifyJS confirm is not working with Angular 8为什么 AlertifyJS 确认不适用于 Angular 8
【发布时间】:2020-02-21 04:07:23
【问题描述】:

我已经使用我的 Angular 应用程序正确设置了 AlertJS,它对我的​​成功、错误和警报很有用。但是,我设置确认方法的方式无法正常工作。

这是我的 AlertJS 服务的实现

confirm(title: string, message: string, okCallback: () => any, cancelCallback: () => any) {
    alertify.confirm(title, message, (e: any) => {
      if (e.button.text === 'OK') {
        okCallback();
      } else {
        cancelCallback();
      }
    });
  }

  success(message: string) {
    alertify.success(message);
  }

  error(message: string) {
    alertify.error(message);
  }

  warning(message: string) {
    alertify.warning(message);
  }

  message(message: string) {
    alertify.message(message);
  }

  alert(title: string, message: string, movable: boolean) {
    alertify.alert(title, message).set('movable', movable);
  }

在我的组件中,我正在调用 AlertifyJS 的确认方法,如下所示:

this.alertify.confirm('Success!',
                      'Secret questions/answers have been saved!, would you like to setup a new password?',
                      () => {
                              this.isActive = false;
                              this.isCreateNewPassword = true;
                            },
                      () => {
                              this.router.navigate(['/registrations']);
                            });

它没有正确填充标题。相反,它将它保持为默认值,并将“成功”这个词作为我的信息。

当我从实现和调用中删除标题作为参数时,确认会按预期工作!

知道如何解决这个问题吗?

【问题讨论】:

    标签: angular angular8 alertifyjs


    【解决方案1】:

    confirm 方法的实现应该是这样的

    confirm(title: string, message: string, okCallback: () => any, cancelCallback: () => any) {
        alertify.confirm(title, message, () => { okCallback(); }
                    , () => { cancelCallback(); });
      }
    

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 2015-04-23
      • 1970-01-01
      • 2020-09-30
      • 2022-01-11
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多