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.
This error often means that you haven't declared the directive "x" or haven't imported the NgModule to which "x" belongs. Perhaps you declared "x" in an application sub-module but forgot to export it.
Solution for Angular Can't bind to 'ngIf' since it isn't a known property of 'div' There are multiple ways to fix this. Incorrect ngIf syntax One way, This is due to an error caused due to misspelling capital 'I' for div. To solve this, Import CommonModule or BroswerModule or both into app.
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"; }
Use angular's attribute binding syntax.
Use one of the following:
<button data-toggle="collapse" attr.data-target="#demo{{RowIndex}}">Toggle </button>
or
<button data-toggle="collapse" [attr.data-target]="'#demo' + RowIndex">Toggle </button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With