0

HTML <ng-container *ngFor="let permission of perm.values" [(ngModel)]="permissions = permission">

TS permissions: [];

Hi, I have this container in template and I have a permissions list in TS. I wanted to fill that permissions field with the values I get from '*ngFor'. How can I do that?

3 Answers3

1

You can use the permission inside the ng-continer like that:

<ng-container *ngFor="let permission of perm.values">
<p> {{permission}} </p>
</ng-container>

If you need more information take a look at this.

Nik
  • 56
  • 5
0

One approach is implementing a shared service as explained here;

Another approach is injecting data as you can find here;

I came across a feature request for *ngComponentOutletInput and *ngComponentOutletOutput in addition of *ngComponentOutlet but it seems still to be WIP even if it has been argument of debate for years: in the mean while this project (ng-dynamic-component) looks well mantained and not a joke.

This approach (a custom directive) is also very interesting.

Nik Rubblers
  • 142
  • 1
  • 13
-1

your approach is off. in your component, you should fill your permissions array with the values:

this.permissions = [...this.perm.values];

then just iterate permissions in your ngFor

<ng-container *ngFor="let permission of permissions" [(ngModel)]="permission">
bryan60
  • 28,215
  • 4
  • 48
  • 65