javascript - 使用多个 Bootstrap 模式时出现问题(ngx-bootstrap 和 Angular)

标签 javascript twitter-bootstrap angular modal-dialog ngx-bootstrap

我在 Angular 4 中使用多个 Bootstrap 模式确实遇到了问题。也许你可以帮助我解决这个问题。该代码仅适用于一种模式。我无法使用第一个加载的模式的按钮/表单。第二个工作正常。打开和关闭第二个模态后,第一个模态也起作用......奇怪。有什么不对?

<!-- ADD MODAL-->
<div bsModal #addModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myAddModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Add Dimension</h4>
        <button type="button" class="close" (click)="addModal.hide()" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="formGroupInput">TAG</label>
            <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" aria-describedby="keyHelp"
              value="" disabled>
            <small id="keyHelp" class="form-text text-muted">Notice that this field is a surrogate key!</small>
          </div>
          <div class="form-group">
            <label for="formGroupInput2">Name</label>
            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" value="">
          </div>
          <div class="form-group">
            <label for="formGroupInput3">Description</label>
            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" value="">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" id="dfsdfsdfsdf" class="btn btn-secondary" (click)="addModal.hide()">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<!-- EDIT MODAL-->
<div bsModal #editModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Edit {{currentItem?.NAME}}</h4>
        <button type="button" class="close" (click)="editModal.hide()" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="formGroupInput">TAG</label>
            <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" aria-describedby="keyHelp"
              value="{{currentItem?.TAG}}" disabled>
            <small id="keyHelp" class="form-text text-muted">You'll need to delete this entry to change this key value!</small>
          </div>
          <div class="form-group">
            <label for="formGroupInput2">Name</label>
            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" value="{{currentItem?.NAME}}">
          </div>
          <div class="form-group">
            <label for="formGroupInput3">Description</label>
            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" value="{{currentItem?.COMM}}">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" (click)="editModal.hide()">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

import { Component, OnInit, ViewChild } from '@angular/core';
import { DataService } from "../data.service";
import { ModalDirective } from 'ngx-bootstrap/modal/modal.component';

@Component({

  templateUrl: './dimensions.component.html',
  styleUrls: ['./dimensions.component.scss']
})
export class DimensionsComponent implements OnInit {

  @ViewChild('editModal') public editModal: ModalDirective;
  @ViewChild('addModal') public addModal: ModalDirective;
  currentItem;

  openModal(item: any) {
    this.currentItem = item;
    this.editModal.show();

  }


  openAddModal() {
    this.addModal.show();

  }


  //Attributes
  public currentVar;
  subscription;
  dimensionData;
  rows;

  constructor(private _dataService: DataService) {


  }

谢谢你们的宝贵时间!

更新:通过切换代码内的模式序列,也会出现问题,但只是在其他模式方面。

最佳答案

bsModal 指令并不真正适合嵌套模态,请转换为 bsModal 服务的用法,请参阅此处的示例: https://valor-software.com/ngx-bootstrap/#/modals#service-nested

关于javascript - 使用多个 Bootstrap 模式时出现问题(ngx-bootstrap 和 Angular),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46360937/

相关文章:

javascript - 使用 Vue 组件 - setattr - 无效的属性名称

CSS - jQuery Layout & Bootstrap 3 - Z-Index 问题?

html - Bootstrap 和 Normalize.css : spacing problems

jquery - Bootstrap 模态未显示但似乎已打开

angular - 在 angular\cli 中使用 ng2-ckeditor

Javascript更改div中跨度的文本

javascript - 如何在videojs中以编程方式添加RemoteTextTrack

node.js - Nestjs 错误 : Cannot find module './app.controller'

javascript - 将一个 div 堆叠在隐藏在滚动条上的 Bootstrap 导航栏之上

css - 在 Angular 包中包含 CSS 文件