【发布时间】:2018-11-25 15:31:01
【问题描述】:
我正在尝试使用 ng-bootstrap 4 在我的 Angular 7 应用程序中创建模态,但模态组件一直在后台作为 div 打开,而不是作为模态。我做错了什么?
这是组件打开模式:
import { Component, OnInit } from '@angular/core';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { FormBuilder, FormGroup, Validators} from '@angular/forms';
import { AddPetModalComponent } from '../add-pet-modal/add-pet-modal.component';
import { Pet } from '../../models/pet';
import { PetsService } from '../../services/pets.service';
@Component({
selector: 'app-pets-list',
templateUrl: './pets-list.component.html',
styleUrls: ['./pets-list.component.less']
})
export class PetsListComponent implements OnInit {
petForm: FormGroup;
pets: Pet[];
closeResult: string;
constructor(
private formBuilder: FormBuilder,
private petService: PetsService,
private modalService: NgbModal,
) { }
openFormModal() {
const modalRef = this.modalService.open(AddPetModalComponent);
modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}
模态组件:
import { Component, OnInit } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-add-pet-modal',
templateUrl: './add-pet-modal.component.html',
styleUrls: ['./add-pet-modal.component.less']
})
export class AddPetModalComponent implements OnInit {
constructor(
public activeModal: NgbActiveModal
) { }
ngOnInit() {
}
closeModal() {
this.activeModal.close('Modal Closed');
}
}
github上的模块链接:https://github.com/Strzesia/Daily-Rat-Monitor/tree/fix/src/app/pets
【问题讨论】:
-
你能在 stackblitz 中重现这个问题吗?
-
您能否提供应用程序或调试器中 DOM 的屏幕截图,并解释您遇到的真正问题是什么?
标签: javascript angular modal-dialog bootstrap-modal ng-bootstrap