相关疑难解决方法(0)

How to Send FormGroup Object as Output to Parent Component from child component n Angular

I'm working in forms and I have two components: my child component contains this formGroup Object :

employeeForm : FormGroup;
this.employeeForm = new FormGroup({
       firstName:new FormControl(),
       lastNAme:new FormControl(),
       email:new FormControl()
    });
Run Code Online (Sandbox Code Playgroud)

the child Component conatins just a small part of the form and the parent componant, contains the global form with submit button..

my issue is: I want in the Parent Component when I click on submit button I get the form group from my child component and push it …

typescript angular-components angular angular-forms angular6

10
推荐指数
2
解决办法
7530
查看次数

如何使用当前的Form API将父组件的FormGroup传递给其子组件

我想将父组件的FormGroup传递给它的子组件,以便使用子组件显示错误消息

鉴于以下父母

parent.cmponent.ts

import { Component, OnInit } from '@angular/core'
import {
    REACTIVE_FORM_DIRECTIVES, AbstractControl, FormBuilder, FormControl,
    FormGroup, Validators
} from '@angular/forms'

@Component(
    {
      moduleId: module.id,
      selector: 'parent-cmp',
      templateUrl: 'language.component.html',
      styleUrls: ['language.component.css'],
      directives: [
        ErrorMessagesComponent]
    })
export class ParentCmp implements OnInit {
  form: FormGroup;
  first: AbstractControl;
  second: AbstractControl;

  constructor(private _fb: FormBuilder) {
    this.first =
        new FormControl('');
    this.second = new FormControl('')
  }

  ngOnInit() {
    this.form = this._fb.group(
        {
          'first': this.first,
          'second': this.second
        });
}
}
Run Code Online (Sandbox Code Playgroud)

我现在想将表单:FormGroup变量传递给下面的子组件

错误message.component.ts

import { Component, OnInit, Input …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-forms typescript1.8 angular

7
推荐指数
5
解决办法
1万
查看次数