简体   繁体   中英

Add HTML to dynamic elements using angular2

I need to append dynamic html in angular with in loop.

As I am trying to use in following way, but getting issue

<div class="reseipt panel panel-default" *ngFor="let goal of goals">

    <p class="panel-heading" data-toggle="collapse" data-target="
     {{'#collapse-'+ goal.Id}}">
     Goal - {{goal.Description}} {{goal.Id}}
   </p>

While try to add this code I am getting following issue:

Can't bind to 'target' since it isn't a known property of 'p'. ("ult" *ngFor="let goal of goals">

Please suggest how can I resolve this.

Thanks.

Try this

<div class="reseipt panel panel-default" *ngFor="let goal of goals">
            <p class="panel-heading" data-toggle="collapse" 
    [attr.data-target]="'#collapse-'+ goal.Id">Goal - {{goal.Description}} {{goal.Id}}</p>

data-target is not html5 attributes it is used by bootstrap. So Angular giving you error about it. more detail

Try this

<div class="reseipt panel panel-default" *ngFor="let goal of goals">

            <p class="panel-heading" data-toggle="collapse" 
[attr.data-target]="'#collapse-'+ goal.Id"> Goal - {{goal.Description}} {{goal.Id}}</p>

To tell Angular explicitly to use attribute binding, use instead above code using attr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM