[英]Why does my modal open in the background?
I'm trying to make a modal in my angular 7 app using ng-bootstrap 4, but the modal component keeps opening in the background as a div, not as a modal. 我正在尝试使用ng-bootstrap 4在我的angular 7应用程序中创建模态,但是模态组件会在div中以div(而不是模态)的形式在后台继续打开。 What am I doing wrong? 我究竟做错了什么?
this is the component opening modal: 这是组件打开模式:
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);
});
}
modal component: 模态成分:
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');
}
}
link to the module on github: https://github.com/Strzesia/Daily-Rat-Monitor/tree/fix/src/app/pets 链接到github上的模块: https : //github.com/Strzesia/Daily-Rat-Monitor/tree/fix/src/app/pets
I took a look around your code quickly and you seem to include essentials, I got it working though with no problems with this Stackblitz . 我快速浏览了一下您的代码,您似乎包含了一些要点,尽管此Stackblitz没问题,但我可以正常工作。 Some pointers that might help you: 一些可以帮助您的指针:
entryComponents: [ AddPetModalComponent ]
as you are dynamically populating the modal with a component factory. 在您的app.module中,您缺少entryComponents: [ AddPetModalComponent ]
因为您正在使用组件工厂动态填充模态。 Hope some of the points help! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.