0

I am new to angular and I am currently using Angular 7. I can't add the variable to data-link property.

In my ts file I have a variable :

export class PortfolioComponent implements OnInit {
     var = "#item1";
} 

And in HTML I have:

<li class="item group1" data-link="{{var}}">
        text
</li>

But this doesn't work, and shows the following error:

Can't bind to 'link' since it isn't a known property of...

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40

1 Answers1

0

The var is reserved word in javascript - typescript so you can't use it like this.

The var statement declares a variable.

You can find all reserved words here enter link description here

This is how your code will work:

TS

export class PortfolioComponent implements OnInit {
     element = "#item1"; // Change var to anything not reserved
} 

HTML

<li class="item group1" data-link="{{element}}">
        text
</li>
Srdjan
  • 584
  • 3
  • 6
  • Thank you , Var is just an example , even when i try element not worknig i just find the correct answer , we should but attar befor the unknown property to be (( attr.data-link )) that solve the problem in case anyone go throw it .. – Ghada Rahhal Jan 29 '19 at 09:19