Alertify Error "ReferenceError: alertify is not defined " in Angular 6

Alertify Error "ReferenceError: alertify is not defined " in Angular 6

我尝试在我的项目中使用alertify.js。所以我遵循了这个material https://signl.uk/tutorial/index/notify-service-with-angular-5。但是在我的应用程序中单击按钮时出现错误 ReferenceError: alertify is not defined

alertifyjs css 和我添加到 angular.json 文件中的 js 文件。

alertify.service.ts

帮我找出错误。

编辑

我在 component.ts 文件中导入 AlertifyService 作为 private alertify: AlertifyService 并在应用程序模块中 import { AlertifyService } from './services/alertify.service'; 并在提供者中添加 AlertifyService 作为 providers: [AlertifyService]

我在我的登录组件中使用了 alertify

登录.component.ts

login(){
let email = this.loginForm.get("email").value;
let password = this.loginForm.get("password").value;
this.loading = true;
this.authService.login(email, password).subscribe(response => {

  this.alertify.success('Successfully Login');

  this.loading = false;

  // Save data to sessionStorage
  localStorage.setItem('isLoggedIn', "true");
  localStorage.setItem('currentUserID', response.user.uid);
  this.router.navigate(['/dashboard'])
}, error => {
  this.loading = false;
 });
}
  1. 重启服务器。

  2. 如果出现类似

    的错误

    no such file or directory, open 'D:\testProject\node_modules\alertifyjs\build\alertify.min.js'

然后 更改

"../node_modules/bootstrap/dist/css/bootstrap.min.css", "../node_modules/alertifyjs/build/css/alertify.min.css", "../node_modules/alertifyjs/build/css/themes/bootstrap.min.css",

"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/alertifyjs/build/css/alertify.min.css",
"./node_modules/alertifyjs/build/css/themes/bootstrap.min.css",

您应该添加到构建下的脚本部分 part.Probably 您正在添加测试部分。(在 angular.json 中)

"build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/shop",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "aot": false,
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.css"
        ],
        "scripts": [
          "node_modules/alertifyjs/build/alertify.min.js"

        ]
      },

在我的例子中,我在 styles.css 和 angular.json 上都使用了 alertify.js 而不是 alertifyjs。

@import "~alertify.js/build/css/themes/bootstrap.min.css"; 

"./node_modules/alertify.js/build/alertify.min.js"