This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addNewAdmin(){ | |
this.admins.push(this.adminForm); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button type="button" (click)="addNewAdmin()">Add</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngFor="let adminForm of admins.controls; let index = index"> | |
<div> | |
<input id="name" type="text" formControlName="name" /> | |
<input id="email" type="text" formControlName="email" /> | |
</div> | |
</ng-container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div [formGroup]="companyForm"> | |
<div> | |
<label for="companyName">Company Name</label> | |
<input id="companyName" type="text" formControlName="companyName" /> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormArray, FormBuilder, FormControl, Validators } from '@angular/forms'; | |
@Component({ | |
selector: 'app-company-view', | |
templateUrl: './company-view.component.html', | |
styleUrls: ['./company-view.component.scss'] | |
}) | |
export class CompanyViewComponent implements OnInit { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get admins() { | |
return this.companyForm.controls["admins"] as FormArray; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
companyForm = this.fb.group({ | |
companyName: new FormControl('', [Validators.required]), | |
admins: this.fb.array({}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(private fb: FormBuilder) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'app-company-view', | |
templateUrl: './company-view.component.html', | |
styleUrls: ['./company-view.component.scss'] | |
}) | |
export class CompanyViewComponent implements OnInit { | |
constructor(){} | |