【问题标题】:Alertify with Angular change dialog title使用 Angular 更改对话框标题发出警报
【发布时间】:2020-02-23 03:53:57
【问题描述】:

我的 Angular 8 项目中有 Alertify。现在我想更改调用alertify.alert 时出现的对话框中的标题。文档说这可以通过使用接受标题的重载来完成:alertify.alert('Title', 'Message') 但是当我尝试使用它时,IDE 已经告诉我这是无效的参数数量,并且在运行时消息框仍然出现,但是标题未设置。

这是怎么做到的?

编辑 1

版本:

  • 角度:7.3.8
  • Alertifyjs:1.12.0

我是如何集成它的:

angular.json

"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"src/styles.css"
],
"scripts": [
"node_modules/alertifyjs/build/alertify.min.js"
]

styles.css中的条目

@import "../node_modules/alertifyjs/build/css/alertify.min.css";
@import "../node_modules/alertifyjs/build/css/themes/bootstrap.min.css";

服务:

Import {Injectable} from '@angular/core';

declare let alertify: any;

@Injectable({
  providedIn: 'root'
})

export class AlertifyService {

  constructor() {
  }

  error(message: string) {
    alertify.alert('MyApp', message);
  }
}

【问题讨论】:

  • 正如您所说,alertify 中的该方法确实需要两个参数,文档中提到了它。所以这可能不是问题,所以也许你可以分享更多你的代码?也许您导入库的方式可能是问题所在,我不知道,但从您提供的信息中无法分辨出问题所在。这可能就是人们一直对你投反对票的原因。
  • 您还必须确保您使用的 alertify 版本与您使用的文档版本相匹配。并且还要检查类型在DefinitelyTyped repo中创建的版本
  • 好的...我明白了。我没有添加代码的原因是因为这是他们在他们的页面上推荐的基本实现。反正我现在加了。谢谢。

标签: angular alertifyjs


【解决方案1】:

我想通了。问题是脚本条目:

错误:

"scripts": [
  "node_modules/alertifyjs/build/alertify.min.js"
]

正确:

"scripts": [
  "./node_modules/alertifyjs/build/alertify.min.js"
]

有趣的是,alertify 确实以某种方式使用了错误的行

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多