Can't bind variable to string

284 Views Asked by At

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...

1

There are 1 best solutions below

1
On

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>