4

I try to use alertify.js in my project .So I followed this material https://signl.uk/tutorial/index/notify-service-with-angular-5. But I got a error ReferenceError: alertify is not defined when click button in my application.

alertifyjs css and js files I add into angular.json file.

![enter image description here

alertify.service.ts

![enter image description here

Help me for identify my mistake.

Edit

I import AlertifyService in component.ts file as private alertify: AlertifyService and In app module import { AlertifyService } from './services/alertify.service'; and added AlertifyService in provider as providers: [AlertifyService]

I use alertify in my login component

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;
 });
}
16
  • try import * as alertify; Commented Sep 20, 2018 at 8:34
  • 1
    did you restart ng serve after adding the script to angular.json ? Commented Sep 20, 2018 at 8:45
  • 1
    Can you please check if alertify.min.js exists on the given path? Commented Sep 20, 2018 at 8:51
  • 1
    I've seen that tutorial too, the problem for me was that alertify is discontinued, and therefore even though bower recognizes it, the .js files don't get downloaded. You should google alertify.js, download the scripts manually and place them into the folder your app would look for them. Commented Sep 20, 2018 at 9:00
  • 1
    check the path, i think the path you have provided is not correct. Can you share your folder structure? Commented Sep 20, 2018 at 9:47

3 Answers 3

3
  1. Restart server.

  2. If get error like

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

then Change

"../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",

to

"./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",
Sign up to request clarification or add additional context in comments.

Comments

2

you should add to scripts section under the build part.Probably you are adding test section.(in 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"

        ]
      },

1 Comment

This does not provide an answer to the question. You can search for similar questions, or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, ask a new question, and include a link to this one to help provide context. See: Ask questions, get answers, no distractions
0

In my case, instead of alertifyjs I used alertify.js on both styles.css and angular.json.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.