I get the error "Cannot find a differ supporting object 'width: 100%' " when I try to use style with p-menu or p-dropdown .
Asked
Active
Viewed 1.4k times
18
-
can you specify which style property are you setting on p-menu? – Shubhi Sood Jun 07 '18 at 09:31
-
style="width: 40%" width property – Hima Susan Jun 07 '18 at 10:05
4 Answers
35
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>

sawprogramming
- 737
- 1
- 9
- 15
-
This answer returns also true for the DynamicDialog component in primeng (used at v.7.0.5). – j4v1 Apr 23 '19 at 13:19
-
1For 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. – Experimenter Feb 01 '22 at 15:35
-
1
6
https://github.com/primefaces/primeng/commit/b774ab2a5811b223c49dcef55ba84bcbcfa09579
- check primeNg version.
- if the version is more than 8.1.1
- update p-button style value(string) to objects.
++ [ngStyle] also works
<p-button
label="button"
[style]="{float: 'left'}"
styleClass="ui-button-info" ></p-button>

Energy
- 940
- 13
- 20
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%' }
});

edalvb
- 581
- 6
- 7
-3
That's because [style] takes a string, so you need to write [style]="'width: 40%'"

petronius
- 451
- 3
- 11