alflashy
alflashy

Reputation: 81

Angular 2+ dynamic value with in ngFor tag

I have ngFor loop with attribute disable true on some element and the value come from array which ngFor is running. But I can only get that value inside ngFor tag but not on its own. Here is the sample code

<div ngFor="link in links.linkArr" disable='link.disbleLink'> //can't get the value here
 <div>
  {{link.disbleLink}} // works here
 </div>
</div>

Upvotes: 1

Views: 268

Answers (3)

Ayoub k
Ayoub k

Reputation: 8868

<div *ngFor="link in links.linkArr" [attr.disable]="link.disbleLink">
   <div>
       {{link.disbleLink}}
   </div>
</div>

or you can just use brackets :

<div *ngFor="link in links.linkArr" disable="{{link.disbleLink}}">
   <div>
       {{link.disbleLink}}
   </div>
</div>

Upvotes: 0

Farhad
Farhad

Reputation: 226

For binding dynamic variable in html and use angular you have two way: 1st: [disable]="variableName". 2nd: disable="{{variableName}}". But another important thing is that disable attribute is not available on div tag! https://angular.io/guide/template-syntax

Upvotes: 1

Amit Chigadani
Amit Chigadani

Reputation: 29705

You have written a complete wrong syntax of ngFor. Please go through the docs

<div *ngFor="let link of links.linkArr" [attr.disabled]="link.disbleLink">
   <div>
       {{link.disbleLink}}
   </div>
</div>

Upvotes: 1

Related Questions