Html 在angular 2中,如何将值从子组件传递到父组件?
我需要从子组件获取数据。我的子组件具有popu格式的窗体。如何将完整详细信息传递给父组件。 我的父组件ts文件是Html 在angular 2中,如何将值从子组件传递到父组件?,html,angular,Html,Angular,我需要从子组件获取数据。我的子组件具有popu格式的窗体。如何将完整详细信息传递给父组件。 我的父组件ts文件是 import { Component, OnInit } from '@angular/core'; import {MdDialog, MdDialogRef} from '@angular/material'; @Component({ selector: 'app-vehicle-relocate', templateUrl: './vehicle-r
import { Component, OnInit } from '@angular/core';
import {MdDialog, MdDialogRef} from '@angular/material';
@Component({
selector: 'app-vehicle-relocate',
templateUrl: './vehicle-relocate.component.html',
styleUrls: ['./vehicle-relocate.component.css'],
})
export class VehicleRelocateComponent implements OnInit {
lat: number = 11.074529;
lng: number = 78.003917;
zoom: number = 14;
ngOnInit() {
}
selectedOption: string;
constructor(public dialog: MdDialog) {}
openDialog() {
let dialogRef = this.dialog.open();
dialogRef.afterClosed().subscribe(result => {
this.selectedOption = result;
});
}
}
我的子组件位于父组件中
import { Component, OnInit, Input } from '@angular/core';
import {MdDialog, MdDialogRef} from '@angular/material';
@Component({
selector: 'app-relocate-form',
templateUrl: './relocate-form.component.html',
styleUrls: ['./relocate-form.component.css']
})
export class RelocateFormComponent implements OnInit {
constructor(public dialogRef: MdDialogRef<RelocateFormComponent>) {}
@Input() title:string;
ngOnInit() {
}
}
您可以向子组件添加输出。
例如:@Output notifySubmit:EventEmitter=new EventEmitter如果不需要“any”,则可以放置任何类型的EventEmitter
然后,在子组件中提交表单时,必须将输出通知父组件:
现在您必须在父组件中接收事件。从VehicleRelocateComponent调用RelocateFormComponent时,需要将函数传递到输出
myFunction$Event必须位于父组件中。$event参数等于随this.notifySubmit.emitmyValues一起发送的值 会有帮助吗?哪一个是子组件?第二个是子组件component@JuliaPassynkova我可以看到它,但我的问题是不能在ts文件中使用多个组件我想将完整的html模板从子元素传递到父元素弹出元素有没有一种方法可以对路由参数执行此操作?
this.notifySubmit.emit(myValues)
<app-relocate-form (notifySubmit)="myFunction($event)" ... ></app-relocate-form>