dimakuba / ng-noty

ng-noty is a service for displaying notifications
0 stars 1 forks source link

facing "Noty - not defined" error #1

Open tony-stark001 opened 6 years ago

tony-stark001 commented 6 years ago

Hi, I have followed the readme instructions & imported it to a component to check.But i'm facing "Noty - is not defined" error. Complete error description which I got in console is below.

ERROR ReferenceError: Noty is not defined
    at NgNoty.create (ng-noty.ts:11)
    at NotifyService.openNgNoty (notify.service.ts:21)
    at SafeSubscriber.eval [as _next] (login.component.ts:48)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:238)
    at SafeSubscriber.next (Subscriber.js:185)
    at Subscriber._next (Subscriber.js:125)
    at Subscriber.next (Subscriber.js:89)
    at CatchSubscriber.Subscriber._next (Subscriber.js:125)
    at CatchSubscriber.Subscriber.next (Subscriber.js:89)
    at MapSubscriber._next (map.js:83)

My complete code, app.module.ts

import {NgNoty, NotyOptions} from "ng-noty";

@NgModule({
    ...
  providers: [NgNoty]
  ...
})

notify.service.ts

import { Injectable,Component } from '@angular/core';
import {NgNoty, NotyOptions} from "ng-noty";
@Component({
  selector: 'app-notification',
  template: `
    <button (click)="openNgNoty()" aria-label="Show an example ng-noty">
      Show ng-noty
    </button>
  `,
})

@Injectable()
export class NotifyService {

  constructor(public ngNoty: NgNoty) { }

  openNgNoty() {
    console.log('check'); // console works

    this.ngNoty.create(<NotyOptions>{ // Facing error here
        text: 'Some notification text'
    }).show();
  }

}

login.component.ts

...
import { NotifyService } from '../notify.service';

...

export class LoginComponent implements OnInit {

    constructor(private notify:NotifyService) {}

    onSubmit() {
        cnosole.log('check'); // console works
    this.notify.openNgNoty();
  }

}

Did I do anything wrong or what may be the problem ?

Regards, Deepak

dimakuba commented 6 years ago

Make sure that you included noty.js into your project.

If you're using webpack, you can include Noty.js using ProvidePlugin:

plugins: [
  new webpack.ProvidePlugin({
    "Noty": "noty"
  }),
]