【发布时间】:2018-09-20 08:30:43
【问题描述】:
我尝试在我的项目中使用 alertify.js。所以我遵循了这个材料https://signl.uk/tutorial/index/notify-service-with-angular-5。但是在我的应用程序中单击按钮时出现错误ReferenceError: alertify is not defined。
alertifyjs css 和 js 文件我添加到 angular.json 文件中。
alertify.service.ts
帮我找出我的错误。
编辑
我在 component.ts 文件中将 AlertifyService 导入为 private alertify: AlertifyService 并在应用程序模块中导入 import { AlertifyService } from './services/alertify.service'; 并在提供程序中添加 AlertifyService 作为 providers: [AlertifyService]
我在我的登录组件中使用 alertify
login.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;
});
}
【问题讨论】:
-
试试
import * as alertify; -
脚本添加到
angular.json后是否重启ng serve? -
您能否检查给定路径上是否存在
alertify.min.js? -
我也看过那个教程,对我来说问题是 alertify 已停止,因此即使 bower 识别它,.js 文件也不会下载。您应该 google alertify.js,手动下载脚本并将它们放入您的应用程序将查找它们的文件夹中。
-
检查路径,我认为您提供的路径不正确。你能分享你的文件夹结构吗?
标签: angular alertifyjs