-1

Im trying to assign a style that is coming from an object[], if I hardcode the style like [style]="{'text-align':'right'}" then works but if I read it from the object then throws an error, any advice?

<p-column
  *ngFor="let field of item.Fields"
  [field]="field.Name"
  [header]="field.Header"
  [style]="field.Style"
>
</p-column>

Error:

ERROR Error: Cannot find a differ supporting object '{'text-align':'right'}'

Ivan Lopez
  • 87
  • 8

1 Answers1

0

I'm not sure on how this will work because *ngFor supports the binding for the arrays and not the object. When you get the value for the Fields object, explicitly cast it to the array.

Example

someMethod() {
this.someService.get(xyz).subscribe(
      res => {
              this.Fields = [res]. //res is of type object. We did cast to array. You can 
                                   // use it to style.
             }
         )
     }