Custom attribute gives parsing error when using with an angular 2.0.0-beta.0

Akhilesh Kumar picture Akhilesh Kumar · Feb 20, 2016 · Viewed 18.2k times · Source

I'm trying to use custom attribute with angular2 as following

 <a href="javascript:void(0)" title="{{inst.title}}" data-loc="{{inst.actionval}}">

which gives me following error

EXCEPTION: Template parse errors: Can't bind to 'loc' since it isn't a known native property

Answer

Pardeep Jain picture Pardeep Jain · Feb 20, 2016

Angular by default uses property binding but a doesn't have a property data-loc. To tell Angular explicitly to use attribute binding, use instead: try this one may work for you.

<a href="javascript:void(0)" title="{{inst.title}}" [attr.data-loc]="inst.actionval">

or

<a href="javascript:void(0)" title="{{inst.title}}" attr.data-loc="{{inst.actionval}}">