
after click "Load Data" button "Beginner" radio button is not checked as it is already set in code.
even if we are clicking other radio button then value is not upading in below : "Form Values " data.
if we check other radio button then previous radio button not unchecked as it should checked.
see how it is coming in browser:
below is the code
- import { Component, OnInit } from '@angular/core';
- import { FormGroup , FormControl, FormBuilder } from '@angular/forms';
- @Component({
- selector: 'app-create-employee',
- templateUrl: './create-employee.component.html',
- styleUrls: ['./create-employee.component.css']
- })
- export class CreateEmployeeComponent implements OnInit {
- employeeForm : FormGroup;
- constructor(){}
- ngOnInit(): void {
- this.employeeForm = new FormGroup({
- fullName: new FormControl(),
- email : new FormControl(),
- skills : new FormGroup({
- skillName : new FormControl(),
- experienceInYears: new FormControl(),
- proficiency: new FormControl()
- })
- });
- }
- onLoadDataClick(): void {
- this.employeeForm.setValue({
- fullName: 'ajay',
- email : '[email protected]',
- skills:{
- skillName:'.net',
- experienceInYears : 5,
- proficiency: 'beginner'
- }
- })
- }
- onSubmit(): void
- {
- console.log(this.employeeForm.value);
- console.log(this.employeeForm.controls.fullName.touched);
- console.log(this.employeeForm.get('fullName').value);
- }
- }
- class="panel panel-primary">class="panel-heading">
class
="panel-title">Create Employeeclass="panel-body">class="form-group">- ="col-sm-2 control-label" for="fullName"> Full Name
class="col-sm-8">- "fullName" formControlName="fullName" type="text"class="form-control">
class="form-group">- ="col-sm-2 control-label" for="email"> Email
class="col-sm-8">- "email" formControlName="email" type="text"class="form-control">
"skills">class="form-group">- ="col-sm-2 control-label" for="skillName" >Skill
class="col-sm-4">- "text" id="skillName" placeholder="Name" formControlName="skillName" >
- "text" placeholder="Experience in Years " formControlName="experienceInYears" >
class="form-group">- ="col-md-2 control-label">Proficiency
class="col-md-8" >- ="radio-inline">
- "proficiency" type="radio" value="'beginner'" formControlName="proficiency"> Beginner
- ="radio-inline">
- "proficiency" type="radio" value="Intermediate" formControlName="proficiency"> Intermediate
- ="radio-inline">
- "proficiency" type="radio" value="advanced" formControlName="proficiency"> Advanced
class="panel-footer" >class="btn-toolbar">- ="btn btn-primary" type="submit">Save
- ="btn btn-primary" type="button" (click)="onLoadDataClick()">Load Data
"1">
- formGroup
- formControl (fullName)
"padding: 10px" > - touched : {{employeeForm.touched}}
- dirty : {{employeeForm.dirty}}
- valid : {{employeeForm.valid}}
- Form Values : {{employeeForm.value | json}}
"padding: 10px"> - touched : {{employeeForm.get('fullName').touched}}
- dirty : {{employeeForm.get('fullName').dirty }}
- valid : {{employeeForm.get('fullName').valid }}
- Full Name Values : {{employeeForm.get('fullName').value }}

Arvind KushwahaPosted Jun 5, 2020, 12:21 AM
Arvind KushwahaPosted Jun 5, 2020, 12:03 AM