Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 844
Er Vipin Sharma Avatar asked Apr 13 '17 07:04

Er Vipin Sharma


People also ask

Can't bind since it isn't a known property of DIV?

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.

Can't bind to ngIf since it isn't a known property of?

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.


2 Answers

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";    } 
like image 82
Aravind Avatar answered Sep 18 '22 05:09

Aravind


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> 
like image 29
Amit Avatar answered Sep 19 '22 05:09

Amit