No provider for MessageService!

UI Components for Angular
Post Reply
chfux
Posts: 1
Joined: 08 Dec 2019, 19:04

08 Dec 2019, 19:11

Hi, I'm trying to use Toasts in my app. Got everything installed primeng, primeicons.
Also imported Toastmodule in my module and used MessageService in my component to display toasts.

But I cant make it work, I get this error:
ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[RegistroComponent -> MessageService]:
StaticInjectorError(Platform: core)[RegistroComponent -> MessageService]:
NullInjectorError: No provider for MessageService!
importing as: import { MessageService } from "primeng/api";

constructor:

Code: Select all

  constructor(
    public messageService: MessageService
  ) {}
usage:

Code: Select all

this.messageService.add({
              severity: "success",
              summary: "Service Message",
              detail: "Via MessageService"
            });
I don't understand why this is happening, any help appreciated!

voluu
Posts: 1
Joined: 13 Dec 2019, 14:57

13 Dec 2019, 14:59

Hi,

check the documentation: https://www.primefaces.org/primeng/#/toast


You forgot about `providers: [MessageService]`:

Code: Select all

@Component({
  selector: 'app-component',
  templateUrl: './app-component.html',
  styleUrls: ['./app-component.scss'],
  providers: [MessageService]
})

Darshan RL
Posts: 1
Joined: 04 Sep 2020, 16:41

04 Sep 2020, 16:51

Hi all, I was facing the same issue finally resolved the issue by adding "providers: [MessageService]" in component decorator. But this was mentioned in the documentation steps. I'd to come here to find solution for it.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests