I want to show a dialog box when my application starts but I am getting error ReferenceError: $ is not defined even though I have defined it like declare var $: any;. The demo is at https://stackblitz.com/edit/angular-gnwe2c
If you check the console, you'll see the error.
I have defined an DialogComponent which is simply Bootstrap modal in dialog.component.html. It has a method showDialog which call's Bootstrap's modal method $(this.dialogRef.nativeElement).modal('show');.
In app.component.html, I am using the DialogComponent - <app-dialog-box #dialogBox ></app-dialog-box>. The AppComponent takes an Input and depending on the Input, it decides whether to show the dialog box or nott
App.component.ts
ngAfterViewInit(){
if(this.signup!=""){
if(this.signup === "success") {
this.showDialog("Signup was successful")
}else if(this.signup === "error") {
this.showDialog("Error: Signup wasn't successful")
} else {
this.showDialog("Unrecognised message: "+this.signup)
}
}
}
In index.html
<my-app [signup]="'success'">loading</my-app>
Also, in index.html, I am loading all the javascripts and jquery before using my-app so I expect that $ should be available.
UPDATE - Here is an interesting behaviour. When I run the app for first time using https://angular-gnwe2c.stackblitz.io, I don't see the dialog box and see error in console ReferenceError: $ is not defined, But if I change the code (say type an Enter, Stackblitz refreshes the code and the dialog box pops! I think when the app is loading initially, jquery isn't downloaded but when I change the code, jquery is available at that time
https://angular-gnwe2c.stackblitz.io, I don't see the dialog box and see error in consoleReferenceError: $ is not defined, But if I change the code (say type an Enter, Stackblitz refreshes the code and the dialog box pops! I think when the app is loading initially, jquery isn't downloaded but when I change the code, jquery is available at that time.Materialise, I am usingBootstrap.