Angular6 将数据发送到具有模型的组件
嗨,我使用带ng boostrap的Angular 6。 如何在打开弹出窗口时向组件发送数据? 这实际上是在弹出窗口中弹出的 调用堆叠模型 打开弹出窗口的唯一方法是使用modelSerivce.open,并且没有可附加数据的字段。需要这样发送Angular6 将数据发送到具有模型的组件,angular6,ng-bootstrap,Angular6,Ng Bootstrap,嗨,我使用带ng boostrap的Angular 6。 如何在打开弹出窗口时向组件发送数据? 这实际上是在弹出窗口中弹出的 调用堆叠模型 打开弹出窗口的唯一方法是使用modelSerivce.open,并且没有可附加数据的字段。需要这样发送 popUPOrders() { const modelRef = this.modalService.open(OrdersComponent, { size: 'lg' }) modelRef.componentInstance.obj = this
popUPOrders() {
const modelRef = this.modalService.open(OrdersComponent, { size: 'lg' })
modelRef.componentInstance.obj = this.customerObj;}
并在OrdersComponent中创建变量
obj:any;
要传递的数据需要是内容组件的输入属性。在您的情况下,请为OrdersComponent组件添加输入属性。
链接:
引导站点示例(组件作为内容):
从'@angular/core'导入{Component,Input};
从'@ng bootstrap/ng bootstrap'导入{NgbActiveModal,NgbModal};
@组成部分({
选择器:“ngbd模式内容”,
模板:`
你好!
&时代;
你好,{{name}}
接近
`
})
出口类NgbdModalContent{
@输入()名称;
构造函数(public-activeModal:NgbActiveModal){}
}
@组成部分({
选择器:“ngbd模态组件”,
templateUrl:“./modal component.html”
})
导出类NgbdModalComponent{
构造函数(私有modalService:NgbModal){}
开(){
const modalRef=this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name='World';
}
}
obj:any;
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">×</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';
}
}