Can't bind to 'target' since it isn't a known property of 'div'

Er Vipin Sharma picture Er Vipin Sharma · Apr 13, 2017 · Viewed 53.5k times · Source

I am getting this error while implementing collapse feature:

Error: Template parse errors: Can't bind to 'target' since it isn't a known property of 'div'

app.component.html:

<div *ngFor = "let ele of elements; let RowIndex = index">
    {{ele.name}} 
    <button data-toggle="collapse" 
            data-target="#demo{{RowIndex}}">Toggle
    </button>
    <div id="demo{{RowIndex}}" class="collapse">Lorem Ipsum</div>

</div>

But if I simply use data-target="#demo" , that is working fine. But when I am binding {{RowIndex}} than its showing error.

Answer

Aravind picture Aravind · Apr 13, 2017

You missed property binding

<button data-toggle="collapse" 
        [attr.data-target]="'#demo'+ RowIndex">Toggle
</button>


<button (click)="clickMe($event)">Toggle</button>

clickMe(value){
    value.srcElement.innerHTML="Clicked";

  }