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

时间:2018-10-20 13:04:29

标签: angular6 ng-bootstrap

即时通讯将Angular 6与ng-boostrap结合使用。 打开PopUP时如何将数据发送到组件? 这实际上是弹出窗口中的弹出窗口。

调用堆叠模型

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

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

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

2 个答案:

答案 0 :(得分:0)

需要这样发送

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

并在OrdersComponent中创建变量

obj:any;

答案 1 :(得分:0)

要传递的数据需要是内容组件的输入属性。在您的情况下,为OrdersComponent组件添加输入属性。
链接: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';
  }
}