角度attr.data-target和attr.id不起作用

问题描述 投票:2回答:1

我正在尝试使用ngFor为我的引导程序模式分配唯一ID。以下是我的代码。

<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时。模态由于某种原因不会弹出。任何帮助将不胜感激

javascript html angular
1个回答
3
投票

向ID添加“#”。

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

© www.soinside.com 2019 - 2024. All rights reserved.