javascript - Angular attr.data-target and attr.id not working - Stack Overflow

I am trying assign unique id to my bootstrap modal as it's being using ngFor. Following is my code

I am trying assign unique id to my bootstrap modal as it's being using ngFor. Following is my code.

<div class="container shadow lead-container" data-toggle="modal" [attr.data-target]="customId"> -------------------------> . Data-target is set to customId
  <div class="row text-left">
    ----------------------> Other Content goes here
  </div>
</div>

<!--Lead Popup-->
<div class="modal fade" [attr.id]="customId" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> -----------> [attr.id] is set to customid
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="container popup-container">
          <div class="row text-left">

             -------------------------------------> Modal Content Goes Here 
        </div>
      </div>
    </div>
  </div>

Following is my ponent.ts:

import { Lead } from './../models/lead';
import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-lead',
  templateUrl: './leadponent.html',
  styleUrls: ['./leadponent.css']
})
export class LeadComponent implements OnInit {
  @Input() public lead: Lead;
  @Input() public index;
  public customId: string;


  constructor() { 
  }

  ngOnInit() {
    this.customId = "custom".concat(this.index);
  }

}

When i click on div. The modal doesnt popup for some reason. Any help would be much appreciated

I am trying assign unique id to my bootstrap modal as it's being using ngFor. Following is my code.

<div class="container shadow lead-container" data-toggle="modal" [attr.data-target]="customId"> -------------------------> . Data-target is set to customId
  <div class="row text-left">
    ----------------------> Other Content goes here
  </div>
</div>

<!--Lead Popup-->
<div class="modal fade" [attr.id]="customId" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> -----------> [attr.id] is set to customid
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="container popup-container">
          <div class="row text-left">

             -------------------------------------> Modal Content Goes Here 
        </div>
      </div>
    </div>
  </div>

Following is my ponent.ts:

import { Lead } from './../models/lead';
import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-lead',
  templateUrl: './lead.ponent.html',
  styleUrls: ['./lead.ponent.css']
})
export class LeadComponent implements OnInit {
  @Input() public lead: Lead;
  @Input() public index;
  public customId: string;


  constructor() { 
  }

  ngOnInit() {
    this.customId = "custom".concat(this.index);
  }

}

When i click on div. The modal doesnt popup for some reason. Any help would be much appreciated

Share Improve this question asked Nov 15, 2019 at 8:39 Sumanth JoisSumanth Jois 972 silver badges9 bronze badges 7
  • [id]="customId" – Joel Joseph Commented Nov 15, 2019 at 8:54
  • Can you please eloborate? I am new to angular – Sumanth Jois Commented Nov 15, 2019 at 8:54
  • @JoelJoseph dint work tried it – Sumanth Jois Commented Nov 15, 2019 at 8:57
  • have you pass the data of index – Muhammed Albarmavi Commented Nov 15, 2019 at 9:00
  • I am setting the customId in ngOnInit(). And i am passing the data for index – Sumanth Jois Commented Nov 15, 2019 at 9:01
 |  Show 2 more ments

1 Answer 1

Reset to default 5

add "#" to the id.

[attr.data-target]="'#'+customId"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745655585a4638526.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信