Angular 6弹出窗口

时间:2019-03-19 14:06:28

标签: angular angular6

Am正在角度6的弹出窗口中工作。 https://stackblitz.com/angular/brrobnxnooox?file=app%2Fmodal-basic.html

html代码

<div class="form-group">
  <ng-template #ea_popup let-modal>
    <div class="modal-header">
      <h4 class="modal-title" id="modal-basic-title">PopUp</h4>
      <button type="button" class="close" aria-labelledby="Close" (click)="modal.dismiss('Cross click')">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>

    <div class="modal-body">
      <form>
        <div class="form-group">
          <label for="dateOfBirth">Date of birth</label>
          <div class="input-group">
            <input id="dateOfBirth" class="form-control" placeholder="yyyy-mm-dd" name="dp" ngbDatepicker #dp="ngbDatepicker">
            <div class="input-group-append">
              <button class="btn btn-outline-secondary calendar" (click)="dp.toggle()" type="button"></button>
            </div>
          </div>
        </div>
      </form>
    </div>

    <div class="modal-footer">
      <button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')">Save</button>
    </div>
  </ng-template>

  <span></span>
  <button type="submit" class="btn btn-success" (click)="onClick(ea_popup)">Add</button>
</div>

组件代码

import { Component, OnInit, AfterViewInit, ChangeDetectorRef } from '@angular/core';
import { Provider } from '../provider';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
@Component({
    selector: 'app-providerservice',
    templateUrl: './providerservice.component.html',
    styleUrls: ['./providerservice.component.css']
})
export class ProviderserviceComponent implements OnInit {
    constructor(private modalService: NgbModal, public cdRef: ChangeDetectorRef) { }
     closeResult: string;


    ngOnInit() {

    }


    onClic(content) {
         this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
    }


    private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return  `with: ${reason}`;
    }
  }
}

当我在stackblitz中创建一个具有相同代码的项目时,它的工作正常。 当我在项目中实施时,在调试它时会在控制台中显示错误

enter image description here

1 个答案:

答案 0 :(得分:0)

最后,我得到了此问题的解决方案。 更新了index.html文件中的引导CSS,现在可以正常使用了

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">


 to
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">