I am trying to display a toaster notification inside a component. But I am getting this error.
ERROR Error: No provider for ToastsManager!
Following is the code for my component.
JavaScript
x
37
37
1
import { Component, ElementRef, OnInit, ViewContainerRef } from '@angular/core';
2
import { Observable } from 'rxjs/Rx';
3
import * as fullscreen from 'screenfull';
4
import DataService from '../../services/data.service';
5
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
6
7
export interface IProgress {
8
completed?: boolean;
9
customData?: any;
10
position?: number;
11
}
12
13
@Component({
14
selector: 'player',
15
template: require('./player.component.html'),
16
})
17
18
export default class Player implements OnInit {
19
public fileId: string;
20
public token : string;
21
public file: any;
22
public error: any;
23
public loaded: boolean = false;
24
public progress: IProgress;
25
26
constructor(
27
private elementRef: ElementRef,
28
private dataService: DataService,
29
private toastr: ToastsManager,
30
private vcr: ViewContainerRef
31
) {
32
this.toastr.setRootViewContainerRef(vcr);
33
}
34
35
// Other functions
36
}
37
I think there is a problem with injecting ToastsManager
but I can not figure out what has gone wrong.
Can someone please help me?
Advertisement
Answer
Make sure right imports have been made.
JavaScript
1
13
13
1
@NgModule({
2
imports: [
3
BrowserModule,
4
FormsModule,
5
BrowserAnimationsModule, // required animations module
6
ToastrModule.forRoot(), // ToastrModule added
7
],
8
declarations: [AppComponent, HelloComponent],
9
bootstrap: [AppComponent],
10
})
11
export class AppModule {}
12
13