Angular, PrimeNg value p-message is not allowed

2.3k Views Asked by At

Hello got some problem with the p-message Tag in angular. I think ive imported it correctly as i show below.

  import { MessageModule } from 'primeng/message';

  imports: [
    ....
    MessageModule,
    ...

In the html component it is:

  <p-message [value]="message"></p-message>

And in addition, in the ts script it is:

  message: Message[] = [];

Why i got this error, all the time?!

  1. If 'p-message' is an Angular component and it has 'value' input, then verify that it is part of this module.
  2. If 'p-message' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

I want to display the error toastmessage above the inputfield, that someone knows that it already exists.

Thanks in the front for your help guys!

2

There are 2 best solutions below

0
Haseena P A On

p-message only accepts the following parameters - This is to show inline message of any form element

enter image description here

Inorder to show any alert messages you have to use p-messages with value (Message[]) or using the MessageService enter image description here

Makesure you have imported MessagesModule or MessageModule based on your requirement.

If planning to use MessageService, make sure to import in the Providers

0
noxx On

For other that maybe has the same problem. I was initially confused because there are two similarly named modules: MessageModule and MessagesModule.

<p-message severity="error" text="Field is required"></p-message>

<p-messages [(value)]="messages2" [enableService]="false"></p-messages>