Angular 5上的Alertifyjs确认方法失败

时间:2018-08-25 06:00:43

标签: angular alertifyjs

在尝试在我的项目上实现alertifyjs时,在尝试执行/实现确认方法时遇到了奇怪的错误消息:这是我的服务实现:

import { Injectable } from '@angular/core';
declare let alertify: any;

alertify.defaults = {
    // notifier defaults
    notifier: {
        position: 'top-right'
    },
};

@Injectable()
export class AlertifyService {

constructor() { }

confirm(message: string, okCallback: () => any) {

  alertify.confirm(message, function(e) {
      if (e) {
          okCallback();
      }
  });
}

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

当我调用成功,错误或警告方法时,它可以正常工作,但是当尝试调用确认方法时,它将破坏应用程序:

  hello() {
    this.alertify.confirm('Anyone there ?', () => {console.log('hey there ...'); });
  }

错误显示如下: enter image description here

使用alertifyjs版本1.11.1 ...谢谢。

1 个答案:

答案 0 :(得分:1)

将默认值设置为:

参考----> enter image description here

alertify.defaults = {
        // dialogs defaults


        // language resources 
        glossary:{
            // dialogs default title
            title:'AlertifyJS',
            // ok button text
            ok: 'OK',
            // cancel button text
            cancel: 'Cancel'            
        },

        // theme settings
        theme:{
            // class name attached to prompt dialog input textbox.
            input:'ajs-input',
            // class name attached to ok button
            ok:'ajs-ok',
            // class name attached to cancel button 
            cancel:'ajs-cancel'
        }
    };