使用模型将数据发送到组件

Send data to components with Models

嗨,我正在使用 Angular 6 和 ng-boostrap。 打开 PopUP 时如何向组件发送数据? 这实际上是在弹出窗口中弹出。

调用堆叠模型

https://ng-bootstrap.github.io/#/components/modal/examples

popUPOrders() {
this.modalService.open(OrdersComponent, {
  size: 'lg'
});

打开 POPUP 的唯一方法是使用 modelSerivce.open,并且没有用于附加数据的字段。

需要这样发送

 popUPOrders() {
const modelRef = this.modalService.open(OrdersComponent, { size: 'lg' })
modelRef.componentInstance.obj = this.customerObj;}

并在 OrdersComponent 中创建变量

obj:any;

要传递的数据需要是内容的输入属性component.In您的案例为 OrdersComponent 组件添加输入属性。
Link: https://ng-bootstrap.github.io/#/components/modal/examples
Bootstrap 站点示例(组件作为内容):

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

@Component({
  selector: 'ngbd-modal-content',
  template: `
    <div class="modal-header">
      <h4 class="modal-title">Hi there!</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">
      <p>Hello, {{name}}!</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
    </div>
  `
})
export class NgbdModalContent {
  @Input() name;

  constructor(public activeModal: NgbActiveModal) {}
}

@Component({
  selector: 'ngbd-modal-component',
  templateUrl: './modal-component.html'
})
export class NgbdModalComponent {
  constructor(private modalService: NgbModal) {}

  open() {
    const modalRef = this.modalService.open(NgbdModalContent);
    modalRef.componentInstance.name = 'World';
  }
}