无法绑定到“目标",因为它不是"div"的已知属性 [英] Can't bind to 'target' since it isn't a known property of 'div'

查看:131
本文介绍了无法绑定到“目标",因为它不是"div"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实施折叠功能时出现此错误:

I am getting this error while implementing collapse feature:

错误:模板解析错误:由于它不是 div的已知属性

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

app.component.html:

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>

但是,如果我只是使用data-target="#demo",那就很好用了.但是当我绑定{{RowIndex}}而不是它显示错误时.

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

推荐答案

您错过了属性绑定

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


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

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

  }

这篇关于无法绑定到“目标",因为它不是"div"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆