javascript - Angular attr.data-target 和 attr.id 不起作用

标签 javascript html angular

我正在尝试为我的引导模式分配唯一的 id,因为它正在使用 ngFor。以下是我的代码。

<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>

以下是我的component.ts:

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

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


  constructor() { 
  }

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

}

当我点击div时。由于某种原因,模式不会弹出。任何帮助将不胜感激

最佳答案

在 ID 中添加“#”。

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

关于javascript - Angular attr.data-target 和 attr.id 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58873155/

相关文章:

javascript - 尝试使用 TypeScript 为简单的导航栏实现面向对象的设计模型

javascript - 文本区域未被渲染

javascript - 使用 jQuery 将页面滚动到具有特定 href 的 <a>

javascript - 选项卡或窗口之间的通信

javascript - Angular AngularFire2 简单连接

javascript - 需要有关按钮 CSS 的建议

html - 如何让 span 或 li 的背景图像出现在文本上方的顶部?

html - IE 特定样式表打击其他版本的 IE

angular - 将 Angular http 响应转换为类

angular - HttpClient 不返回数据