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.
import { Component, ElementRef, OnInit, ViewContainerRef } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import * as fullscreen from 'screenfull';
import DataService from '../../services/data.service';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
export interface IProgress {
completed?: boolean;
customData?: any;
position?: number;
}
@Component({
selector: 'player',
template: require('./player.component.html'),
})
export default class Player implements OnInit {
public fileId: string;
public token : string;
public file: any;
public error: any;
public loaded: boolean = false;
public progress: IProgress;
constructor(
private elementRef: ElementRef,
private dataService: DataService,
private toastr: ToastsManager,
private vcr: ViewContainerRef
) {
this.toastr.setRootViewContainerRef(vcr);
}
// Other functions
}
I think there is a problem with injecting ToastsManager
but I can not figure out what has gone wrong.
Can someone please help me?
CodePudding user response:
Make sure right imports have been made.
@NgModule({
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule, // required animations module
ToastrModule.forRoot(), // ToastrModule added
],
declarations: [AppComponent, HelloComponent],
bootstrap: [AppComponent],
})
export class AppModule {}