23

I get the error "Cannot find a differ supporting object 'width: 100%' " when I try to use style with p-menu or p-dropdown .

2
  • can you specify which style property are you setting on p-menu? Commented Jun 7, 2018 at 9:31
  • style="width: 40%" width property Commented Jun 7, 2018 at 10:05

4 Answers 4

46

I had this issue when working with the p-confirmDialog, so I looked at their source to see what was going on. PrimeNG passes the value from the [style] attribute as-is to the component's [ngStyle], which takes an object. So, the solution is:

<p-confirmDialog [style]="{'width': '100%'}">
  ...
</p-confirmDialog>

Sign up to request clarification or add additional context in comments.

3 Comments

This answer returns also true for the DynamicDialog component in primeng (used at v.7.0.5).
For me it doesn't work for p-dropdown. I found the next line in Angular Docs about [style]: "When binding [style] to an object expression, the identity of the object must change for Angular to update the class list. Updating the property without changing object identity has no effect." As I understand it's connected. Not find the solution yet.
Changing [style] to [ngStyle] helps me.
6

https://github.com/primefaces/primeng/commit/b774ab2a5811b223c49dcef55ba84bcbcfa09579

  1. check primeNg version.
  2. if the version is more than 8.1.1
  3. update p-button style value(string) to objects.

++ [ngStyle] also works

      <p-button 
      label="button"
      [style]="{float: 'left'}"
      styleClass="ui-button-info" ></p-button>

Comments

0

I was trying to add styles to the content of a DinamicDialog but this worked for me.

this.ref = this.dialogService.open(MyComponent, {
  header: 'contentStyle Header',
  width: '80%',
  height: '80%',
  contentStyle: { height: '100%' }
});

Comments

-4

That's because [style] takes a string, so you need to write [style]="'width: 40%'"

1 Comment

it gives the same result, nothing changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.