42

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

Akhilesh Kumar
  • 9,085
  • 13
  • 57
  • 95
  • 1
    Possible duplicate of [Angular 2 data attributes](http://stackoverflow.com/questions/34542619/angular-2-data-attributes) – Mark Rajcok Feb 20 '16 at 18:07

1 Answers1

108

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}}">
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215