Angular NgModal打开,但不能单击任何输入或按钮

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

问题:我在一个组件内有一个按钮,可以以模式的形式打开另一个组件。该按钮起作用并打开模式,除了我不能单击任何东西,输入或叉号。我已经将该组件作为entryComponent插入到App模块中:

entryComponents: [NeworderComponent]

调用模式窗口的组件.html

<button type="button" class="btn btn-success text-center" (click)="openew(rank?.productId)">Order</button>

调用模式窗口的组件.ts

  import { Component, OnInit } from '@angular/core';
    import { ActivatedRoute, Router } from '@angular/router';
    import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';

    export class TopproductsComponent implements OnInit {

  constructor(private orderservice: OrderService,
    private productService: ProductService,
    private activatedRoute: ActivatedRoute,
    private modalService: NgbModal,
    private router: Router) { }

    openew(id) {
        const modalRef = this.modalService.open(NeworderComponent, {size:"lg"});
        modalRef.componentInstance.title = 'neworder';
      }
}

模态组件.html

<div class="modal-dialog modal-lg">
        <div class="modal-header">
          <h4 class="modal-title">New Order</h4>
            <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
              <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <div class="mt-3">
                <form #new="ngForm" class="mt-3 text-center" id="form" (ngSubmit)="onSubmit(new)">
                    <div class="text-center">
                      <div class="form-group">
                        <label for="prod_edit">Product</label>
                          <select class="form-control" [(ngModel)]="product" [ngModelOptions]="{standalone: true}">
                            <option *ngFor="let product of products" value="{{ product?.id }}" >{{ product?.name }}</option>
                          </select>
                      </div>  
                        <div class="form-group">
                            <label for="exampleFormControlInput1">Quantity</label>
                            <input type="text" name="quantity" class="form-control text-center mt-2" [(ngModel)]="quantity" [ngModelOptions]="{standalone: true}">
                        </div>
                    </div>
                        <button type="submit" class="btn btn-success w-50 mt-2">Submit</button>
                  </form>
            </div>
          </div>
    </div>

模态分量.ts

import { Component, OnInit, Input} from '@angular/core';
import { NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-neworder',
  templateUrl: './neworder.component.html',
  styleUrls: ['./neworder.component.css']
})


export class NeworderComponent implements OnInit {
  @Input() title = `Information`;


  constructor(private orderservice: OrderService,
    private productService: ProductService,
    public activeModal: NgbActiveModal) { }

  ngOnInit() {
    this.productService.getProducts().subscribe(products => {
      this.products = products;
      console.log(this.products);
    });
  }


}
angular typescript modal-dialog ng-modal
1个回答
0
投票

您需要删除组件主div中的类modal-dialog modal-lg(即使您可以删除div)

<div> <!--it's NOT <div class="modal-dialog modal-lg"> -->
 <div class="modal-header">
  ....
  </div>
  <div class="modal-body">
  ...
  </div>
<div>
© www.soinside.com 2019 - 2024. All rights reserved.