<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
>

<channel>
	<title>reactive - Bipon's Diary</title>
	<atom:link href="https://biponnotes.iglyphic.com/tag/reactive/feed/" rel="self" type="application/rss+xml" />
	<link>https://biponnotes.iglyphic.com</link>
	<description>Do good for others. It will come back in unexpected ways.</description>
	<lastBuildDate>Wed, 08 Jan 2020 12:11:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.9.10</generator>
<site xmlns="com-wordpress:feed-additions:1">168324471</site>	<item>
		<title>Diving Deeper into Reactive Forms</title>
		<link>https://biponnotes.iglyphic.com/diving-deeper-into-reactive-forms/</link>
					<comments>https://biponnotes.iglyphic.com/diving-deeper-into-reactive-forms/#respond</comments>
		
		<dc:creator><![CDATA[bipon68]]></dc:creator>
		<pubDate>Wed, 08 Jan 2020 12:11:16 +0000</pubDate>
				<category><![CDATA[Angular Form]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[reactive]]></category>
		<guid isPermaLink="false">https://bipon.me/?p=323</guid>

					<description><![CDATA[<p>Step 1: create-session.component.html initial setup Step 2: create-session.component.ts initial setup Step 3: updated create-session.component.html file Step 4: create-session.component.ts Step 5: create-session.component.html again update for validation</p>
<p>The post <a href="https://biponnotes.iglyphic.com/diving-deeper-into-reactive-forms/">Diving Deeper into Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Step 1: create-session.component.html  initial setup </p>



<pre class="wp-block-code"><code>&lt;div class="col-md-12">
    &lt;h3>Create Session&lt;/h3>
  &lt;/div>
  &lt;div class="col-md-6">
    &lt;form [formGroup]="newSessionForm" (ngSubmit)="saveSession(newSessionForm.value)" autocomplete="off">
      &lt;div class="form-group">
        &lt;label for="sessionName">Session Name:&lt;/label>
        &lt;input id="sessionName" type="text" class="form-control" placeholder="session name..." />
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="eventDate">Presenter:&lt;/label>
        &lt;input id="presenter" type="text" class="form-control" placeholder="presenter..." />
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="duration">Duration:&lt;/label>
        &lt;select class="form-control">
          &lt;option value="">select duration...&lt;/option>
          &lt;option value="1">Half Hour&lt;/option>
          &lt;option value="2">1 Hour&lt;/option>
          &lt;option value="3">Half Day&lt;/option>
          &lt;option value="4">Full Day&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="level">Level:&lt;/label>
        &lt;select class="form-control">
          &lt;option value="">select level...&lt;/option>
          &lt;option value="Beginner">Beginner&lt;/option>
          &lt;option value="Intermediate">Intermediate&lt;/option>
          &lt;option value="Advanced">Advanced&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="abstract">Abstract:&lt;/label>
        &lt;textarea id="abstract" rows=3 class="form-control" placeholder="abstract...">&lt;/textarea>
      &lt;/div>
      &lt;button type="submit" class="btn btn-primary mr-5">Save&lt;/button>
      &lt;button type="button" class="btn btn-default">Cancel&lt;/button>
    &lt;/form>
  &lt;/div></code></pre>



<p> Step 2: create-session.component.ts initial setup</p>



<pre class="wp-block-code"><code>import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
    templateUrl: './create-session.component.html'
})


export class createSessionComponent implements OnInit{

    newSessionForm: FormGroup
    name:FormControl
    presenter: FormControl
    duration:FormControl
    level:FormControl
    abstract:FormControl

    constructor(){}

    ngOnInit(){

        this.name = new FormControl('', Validators.required)
        this.presenter = new FormControl('', Validators.required)
        this.duration = new FormControl('', Validators.required)
        this.level = new FormControl('', Validators.required)
        this.abstract = new FormControl('', [Validators.required, Validators.maxLength(400)])

        this.newSessionForm = new FormGroup({
            name: this.name,
            presenter: this.presenter,
            duration: this.duration,
            level: this.level,
            abstract: this.abstract
        })
    }

    saveSession(formValues){
        console.log(formValues)
    }

}</code></pre>



<p> Step 3:  updated create-session.component.html file</p>



<pre class="wp-block-code"><code>&lt;div class="col-md-12">
    &lt;h3>Create Session&lt;/h3>
  &lt;/div>
  &lt;div class="col-md-6">
    &lt;form [formGroup]="newSessionForm" (ngSubmit)="saveSession(newSessionForm.value)" autocomplete="off">
      &lt;div class="form-group">
        &lt;label for="sessionName">Session Name:&lt;/label>
        &lt;input formControlName="name" id="sessionName" type="text" class="form-control" placeholder="session name..." />
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="eventDate">Presenter:&lt;/label>
        &lt;input id="presenter" type="text" class="form-control" placeholder="presenter..." />
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="duration">Duration:&lt;/label>
        &lt;select formControlName="duration" class="form-control">
          &lt;option value="">select duration...&lt;/option>
          &lt;option value="1">Half Hour&lt;/option>
          &lt;option value="2">1 Hour&lt;/option>
          &lt;option value="3">Half Day&lt;/option>
          &lt;option value="4">Full Day&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="level">Level:&lt;/label>
        &lt;select formControlName="level" class="form-control">
          &lt;option value="">select level...&lt;/option>
          &lt;option value="Beginner">Beginner&lt;/option>
          &lt;option value="Intermediate">Intermediate&lt;/option>
          &lt;option value="Advanced">Advanced&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group">
        &lt;label for="abstract">Abstract:&lt;/label>
        &lt;textarea formControlName="abstract" id="abstract" rows=3 class="form-control" placeholder="abstract...">&lt;/textarea>
      &lt;/div>
      &lt;button type="submit" class="btn btn-primary mr-5">Save&lt;/button>
      &lt;button type="button" class="btn btn-default">Cancel&lt;/button>
    &lt;/form>
  &lt;/div></code></pre>



<p>  Step 4:  create-session.component.ts</p>



<pre class="wp-block-code"><code>import { ISession } from './../shared/event.model';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
    templateUrl: './create-session.component.html',
    styles: [`
    em {float:right; color:#E05C65; padding-left: 10px;}
    .error input {background-color:#E3C3C5;}
    .error ::-webkit-input-placeholder { color: #999; }
    .error ::-moz-placeholder { color: #999; }
    .error :-moz-placeholder { color:#999; }
    .error :ms-input-placeholder { color: #999; }
  `]
})


export class createSessionComponent implements OnInit{

    newSessionForm: FormGroup
    name:FormControl
    presenter: FormControl
    duration:FormControl
    level:FormControl
    abstract:FormControl

    constructor(){}

    ngOnInit(){

        this.name = new FormControl('', Validators.required)
        this.presenter = new FormControl('', Validators.required)
        this.duration = new FormControl('', Validators.required)
        this.level = new FormControl('', Validators.required)
        this.abstract = new FormControl('', [Validators.required, Validators.maxLength(400)])

        this.newSessionForm = new FormGroup({
            name: this.name,
            presenter: this.presenter,
            duration: this.duration,
            level: this.level,
            abstract: this.abstract
        })
    }

    saveSession(formValues){
        // console.log(formValues)
        let session:ISession = {
            id: undefined,
            name: formValues.name,
            presenter:formValues.presenter,
            duration: +formValues.duration,
            level:formValues.lebel,            
            abstract:formValues.abstract,
            voters: []
        }
        console.log(session)
    }

}</code></pre>



<p>Step 5: create-session.component.html again update for validation</p>



<pre class="wp-block-code"><code>&lt;div class="col-md-12">
    &lt;h3>Create Session&lt;/h3>
  &lt;/div>
  &lt;div class="col-md-6">
    &lt;form [formGroup]="newSessionForm" (ngSubmit)="saveSession(newSessionForm.value)" autocomplete="off">
      &lt;div class="form-group" [ngClass]="{'error': name.invalid &amp;&amp; name.dirty}">
        &lt;label for="sessionName">Session Name:&lt;/label>
        &lt;em *ngIf="name.invalid &amp;&amp; name.dirty">Required&lt;/em>
        &lt;input formControlName="name" id="sessionName" type="text" class="form-control" placeholder="session name..." />
      &lt;/div>
      &lt;div class="form-group" [ngClass]="{'error': presenter.invalid &amp;&amp; presenter.dirty}">
        &lt;label for="eventDate">Presenter:&lt;/label>
        &lt;em *ngIf="presenter.invalid &amp;&amp; presenter.dirty">Required&lt;/em>
        &lt;input formControlName="presenter" id="presenter" type="text" class="form-control" placeholder="presenter..." />
      &lt;/div>
      &lt;div class="form-group" [ngClass]="{'error': duration.invalid &amp;&amp; duration.dirty}">
        &lt;label for="duration">Duration:&lt;/label>
        &lt;em *ngIf="duration.invalid &amp;&amp; duration.dirty">Required&lt;/em>
        &lt;select formControlName="duration" class="form-control">
          &lt;option value="">select duration...&lt;/option>
          &lt;option value="1">Half Hour&lt;/option>
          &lt;option value="2">1 Hour&lt;/option>
          &lt;option value="3">Half Day&lt;/option>
          &lt;option value="4">Full Day&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group" [ngClass]="{'error': level.invalid &amp;&amp; level.dirty}">
        &lt;label for="level">Level:&lt;/label>
        &lt;em *ngIf="level.invalid &amp;&amp; level.dirty">Required&lt;/em>
        &lt;select formControlName="level" class="form-control">
          &lt;option value="">select level...&lt;/option>
          &lt;option value="Beginner">Beginner&lt;/option>
          &lt;option value="Intermediate">Intermediate&lt;/option>
          &lt;option value="Advanced">Advanced&lt;/option>
        &lt;/select>
      &lt;/div>
      &lt;div class="form-group" [ngClass]="{'error': abstract.invalid &amp;&amp; abstract.dirty}">
        &lt;label for="abstract">Abstract:&lt;/label>
        &lt;em *ngIf="abstract.invalid &amp;&amp; abstract.dirty &amp;&amp; abstract?.errors.required">Required&lt;/em>
        &lt;em *ngIf="abstract.invalid &amp;&amp; abstract.dirty &amp;&amp; abstract?.errors.maxlength">Cannot exceed 400 character&lt;/em>
        &lt;textarea formControlName="abstract" id="abstract" rows=3 class="form-control" placeholder="abstract...">&lt;/textarea>
      &lt;/div>
      &lt;button [disabled]="newSessionForm.invalid" type="submit" class="btn btn-primary mr-5">Save&lt;/button>
      &lt;button type="button" class="btn btn-default">Cancel&lt;/button>
    &lt;/form>
  &lt;/div></code></pre><p>The post <a href="https://biponnotes.iglyphic.com/diving-deeper-into-reactive-forms/">Diving Deeper into Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://biponnotes.iglyphic.com/diving-deeper-into-reactive-forms/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">323</post-id>	</item>
		<item>
		<title>Multiple Validators in Reactive Forms</title>
		<link>https://biponnotes.iglyphic.com/multiple-validators-in-reactive-forms/</link>
					<comments>https://biponnotes.iglyphic.com/multiple-validators-in-reactive-forms/#respond</comments>
		
		<dc:creator><![CDATA[bipon68]]></dc:creator>
		<pubDate>Mon, 06 Jan 2020 13:19:46 +0000</pubDate>
				<category><![CDATA[Angular Form]]></category>
		<category><![CDATA[angular form]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[reactive]]></category>
		<guid isPermaLink="false">https://bipon.me/?p=316</guid>

					<description><![CDATA[<p>profile.component.html profile.component.ts auth.service.ts user.module.ts user.routes.ts</p>
<p>The post <a href="https://biponnotes.iglyphic.com/multiple-validators-in-reactive-forms/">Multiple Validators in Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><br>
<br>
<!--StartFragment--></p>


<p>profile.component.html</p>



<pre class="wp-block-code"><code>&lt;div>
  &lt;h1>Edit Your Profile &lt;/h1>
  &lt;hr>
  &lt;div class="col-md-4">
    &lt;form [formGroup]="profileForm" (ngSubmit)="saveProfile(profileForm.value)" autocomplete="off" novalidate>
      &lt;div class="form-group" [ngClass]="{'error' : !validateFirstName() }">
        &lt;label for="firstName">First Name:&lt;/label>
        &lt;em *ngIf="!validateFirstName() &amp;&amp; profileForm.controls.firstName.errors.required">Required&lt;/em>
        &lt;em *ngIf="!validateFirstName() &amp;&amp; profileForm.controls.firstName.errors.pattern">Must start with a letter&lt;/em>
        &lt;input formControlName="firstName" id="firstName" type="text" class="form-control" placeholder="First Name..." />
      &lt;/div>
      &lt;div class="form-group"  [ngClass]="{'error' : !validateLastName() }">
        &lt;label for="lastName">Last Name:&lt;/label>
        &lt;em *ngIf="!validateLastName()">Required&lt;/em>
        &lt;input formControlName="lastName" id="lastName" type="text" class="form-control" placeholder="Last Name..." />
      &lt;/div>

      &lt;button type="submit" class="btn btn-primary">Save&lt;/button>
      &lt;button type="button" class="btn btn-default" (click)="cancel()">Cancel&lt;/button>
    &lt;/form>
  &lt;div>
&lt;/div></code></pre>



<p>profile.component.ts</p>



<pre class="wp-block-code"><code>import { Component, OnInit } from '@angular/core'
import { FormControl, FormGroup, Validators } from '@angular/forms'
import { AuthService } from './auth.service'
import { Router} from '@angular/router'

@Component({
  templateUrl: './profile.component.html',
  styles: [`
    em {float:right; color:#E05C65; padding-left: 10px;}
    .error input {background-color:#E3C3C5;}
    .error ::-webkit-input-placeholder { color: #999; }
    .error ::-moz-placeholder { color: #999; }
    .error :-moz-placeholder { color:#999; }
    .error :ms-input-placeholder { color: #999; }
  `]
})
export class ProfileComponent implements OnInit {
  profileForm:FormGroup
  private firstName:FormControl
  private lastName:FormControl

  constructor(private router:Router, private authService:AuthService) {

  }

  ngOnInit() {
    this.firstName = new FormControl(this.authService.currentUser.firstName, [Validators.required, Validators.pattern('[a-zA-Z].*')])
    this.lastName = new FormControl(this.authService.currentUser.lastName, Validators.required)

    this.profileForm = new FormGroup({
      firstName: this.firstName,
      lastName: this.lastName
    })
  }

  saveProfile(formValues) {
    console.log('formValues : ', formValues);
    if (this.profileForm.valid) {
      this.authService.updateCurrentUser(formValues.firstName, formValues.lastName)
      this.router.navigate(['events'])
    }
  }

  validateFirstName() {
    return this.firstName.valid || this.firstName.untouched
  }
  
  validateLastName() {
    return this.lastName.valid || this.lastName.untouched
  }

  cancel() {
    this.router.navigate(['events'])
  }
       
}</code></pre>



<p>auth.service.ts </p>



<pre class="wp-block-code"><code>import { Injectable } from '@angular/core'
import { IUser } from './user.model'

@Injectable()
export class AuthService {

  currentUser:IUser
  
  loginUser(userName: string, password: string) {
    this.currentUser = {
      id: 1,
      userName: userName,
      firstName: 'Bipon',
      lastName: 'Biswas'
    }
  }

  isAuthenticated() {
    return !!this.currentUser;
  }

  updateCurrentUser(firstName:string, lastName:string) {
    this.currentUser.firstName = firstName
    this.currentUser.lastName = lastName
  }
}</code></pre>



<p>user.module.ts</p>



<pre class="wp-block-code"><code>import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'

import { userRoutes } from './user.routes'
import { ProfileComponent } from './profile.component'
import { LoginComponent } from './login.component'

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    RouterModule.forChild(userRoutes)
  ],
  declarations: [
    ProfileComponent,
    LoginComponent
  ],
  providers: [

  ]
})
export class UserModule { }</code></pre>



<p>user.routes.ts</p>



<pre class="wp-block-code"><code>import { ProfileComponent } from './profile.component'
import { LoginComponent } from './login.component'

export const userRoutes = [
  {path: 'profile', component: ProfileComponent},
  {path: 'login', component: LoginComponent}
]</code></pre>


<p><!--EndFragment--><br>
<br>
</p><p>The post <a href="https://biponnotes.iglyphic.com/multiple-validators-in-reactive-forms/">Multiple Validators in Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://biponnotes.iglyphic.com/multiple-validators-in-reactive-forms/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">316</post-id>	</item>
		<item>
		<title>Validating Reactive Forms</title>
		<link>https://biponnotes.iglyphic.com/validating-reactive-forms/</link>
					<comments>https://biponnotes.iglyphic.com/validating-reactive-forms/#respond</comments>
		
		<dc:creator><![CDATA[bipon68]]></dc:creator>
		<pubDate>Mon, 06 Jan 2020 10:01:44 +0000</pubDate>
				<category><![CDATA[Angular Form]]></category>
		<category><![CDATA[angular form]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[reactive]]></category>
		<guid isPermaLink="false">https://bipon.me/?p=314</guid>

					<description><![CDATA[<p>profile.component.html profile.component.ts auth.service.ts user.module.ts user.routes.ts</p>
<p>The post <a href="https://biponnotes.iglyphic.com/validating-reactive-forms/">Validating Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>profile.component.html</p>



<pre class="wp-block-code"><code>&lt;div>
  &lt;h1>Edit Your Profile &lt;/h1>
  &lt;hr>
  &lt;div class="col-md-4">
    &lt;form [formGroup]="profileForm" (ngSubmit)="saveProfile(profileForm.value)" autocomplete="off" novalidate>
      &lt;div class="form-group" [ngClass]="{'error' : !validateFirstName() }">
        &lt;label for="firstName">First Name:&lt;/label>
        &lt;em *ngIf="!validateFirstName()">Required&lt;/em>
        &lt;input formControlName="firstName" id="firstName" type="text" class="form-control" placeholder="First Name..." />
      &lt;/div>
      &lt;div class="form-group"  [ngClass]="{'error' : !validateLastName() }">
        &lt;label for="lastName">Last Name:&lt;/label>
        &lt;em *ngIf="!validateLastName()">Required&lt;/em>
        &lt;input formControlName="lastName" id="lastName" type="text" class="form-control" placeholder="Last Name..." />
      &lt;/div>

      &lt;button type="submit" class="btn btn-primary">Save&lt;/button>
      &lt;button type="button" class="btn btn-default" (click)="cancel()">Cancel&lt;/button>
    &lt;/form>
  &lt;div>
&lt;/div></code></pre>



<p>profile.component.ts</p>



<pre class="wp-block-code"><code>import { Component, OnInit } from '@angular/core'
import { FormControl, FormGroup, Validators } from '@angular/forms'
import { AuthService } from './auth.service'
import { Router} from '@angular/router'

@Component({
  templateUrl: './profile.component.html',
  styles: [`
    em {float:right; color:#E05C65; padding-left: 10px;}
    .error input {background-color:#E3C3C5;}
    .error ::-webkit-input-placeholder { color: #999; }
    .error ::-moz-placeholder { color: #999; }
    .error :-moz-placeholder { color:#999; }
    .error :ms-input-placeholder { color: #999; }
  `]
})
export class ProfileComponent implements OnInit {
  profileForm:FormGroup
  private firstName:FormControl
  private lastName:FormControl

  constructor(private router:Router, private authService:AuthService) {

  }

  ngOnInit() {
    this.firstName = new FormControl(this.authService.currentUser.firstName, Validators.required)
    this.lastName = new FormControl(this.authService.currentUser.lastName, Validators.required)

    this.profileForm = new FormGroup({
      firstName: this.firstName,
      lastName: this.lastName
    })
  }

  saveProfile(formValues) {
    console.log('formValues : ', formValues);
    if (this.profileForm.valid) {
      this.authService.updateCurrentUser(formValues.firstName, formValues.lastName)
      this.router.navigate(['events'])
    }
  }

  validateFirstName() {
    return this.firstName.valid || this.firstName.untouched
  }
  
  validateLastName() {
    return this.lastName.valid || this.lastName.untouched
  }

  cancel() {
    this.router.navigate(['events'])
  }
       
}</code></pre>



<p>auth.service.ts </p>



<pre class="wp-block-code"><code>import { Injectable } from '@angular/core'
import { IUser } from './user.model'

@Injectable()
export class AuthService {

  currentUser:IUser
  
  loginUser(userName: string, password: string) {
    this.currentUser = {
      id: 1,
      userName: userName,
      firstName: 'Bipon',
      lastName: 'Biswas'
    }
  }

  isAuthenticated() {
    return !!this.currentUser;
  }

  updateCurrentUser(firstName:string, lastName:string) {
    this.currentUser.firstName = firstName
    this.currentUser.lastName = lastName
  }
}</code></pre>



<p>user.module.ts</p>



<pre class="wp-block-code"><code>import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'

import { userRoutes } from './user.routes'
import { ProfileComponent } from './profile.component'
import { LoginComponent } from './login.component'

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    RouterModule.forChild(userRoutes)
  ],
  declarations: [
    ProfileComponent,
    LoginComponent
  ],
  providers: [

  ]
})
export class UserModule { }</code></pre>



<p>user.routes.ts</p>



<pre class="wp-block-code"><code>import { ProfileComponent } from './profile.component'
import { LoginComponent } from './login.component'

export const userRoutes = [
  {path: 'profile', component: ProfileComponent},
  {path: 'login', component: LoginComponent}
]</code></pre><p>The post <a href="https://biponnotes.iglyphic.com/validating-reactive-forms/">Validating Reactive Forms</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://biponnotes.iglyphic.com/validating-reactive-forms/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">314</post-id>	</item>
		<item>
		<title>Creating Your First Reactive Form</title>
		<link>https://biponnotes.iglyphic.com/creating-your-first-reactive-form/</link>
					<comments>https://biponnotes.iglyphic.com/creating-your-first-reactive-form/#respond</comments>
		
		<dc:creator><![CDATA[bipon68]]></dc:creator>
		<pubDate>Mon, 06 Jan 2020 09:46:04 +0000</pubDate>
				<category><![CDATA[Angular Form]]></category>
		<category><![CDATA[angular form]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[reactive]]></category>
		<guid isPermaLink="false">https://bipon.me/?p=312</guid>

					<description><![CDATA[<p>profile.component.html profile.component.ts auth.service.ts app.module.ts</p>
<p>The post <a href="https://biponnotes.iglyphic.com/creating-your-first-reactive-form/">Creating Your First Reactive Form</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>profile.component.html</p>



<pre class="wp-block-code"><code>&lt;div>
    &lt;h1>Edit Your Profile &lt;/h1>
    &lt;hr>
    &lt;div class="col-md-4">
      &lt;form [formGroup]="profileForm" (ngSubmit)="saveProfile(profileForm.value)" autocomplete="off" novalidate>
        &lt;div class="form-group">
          &lt;label for="firstName">First Name:&lt;/label>
          &lt;input formControlName="firstName" id="firstName" type="text" class="form-control" placeholder="First Name..." />
        &lt;/div>
        &lt;div class="form-group">
          &lt;label for="lastName">Last Name:&lt;/label>
          &lt;input formControlName="lastName" id="lastName" type="text" class="form-control" placeholder="Last Name..." />
        &lt;/div>
  
        &lt;button type="submit" class="btn btn-primary">Save&lt;/button>
        &lt;button type="button" class="btn btn-default" (click)="cancel()">Cancel&lt;/button>
      &lt;/form>
    &lt;/div>
  &lt;/div></code></pre>



<p>profile.component.ts</p>



<pre class="wp-block-code"><code>import { AuthService } from './auth.service';
import { Component, OnInit } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { Router } from '@angular/router';

@Component({
  templateUrl: './profile.component.html',
})
export class ProfileComponent implements OnInit{

  profileForm: FormGroup

  constructor(private authService: AuthService, private router: Router){}

  ngOnInit(){
    let firstName = new FormControl(this.authService.currentUser.firstName)
    let lastName = new FormControl(this.authService.currentUser.lastName)
    this.profileForm = new FormGroup({
      firstName: firstName,
      lastName: lastName
    })
  }

  cancel(){
    this.router.navigate(['events'])
  }
  saveProfile(formValues){
    this.authService.updateCurrentUser(formValues.firstName, formValues.lastName)
  }     
}</code></pre>



<p>auth.service.ts</p>



<pre class="wp-block-code"><code>import { Injectable } from '@angular/core';
import { IUser } from './user.model';


@Injectable()
export class AuthService{

    currentUser: IUser;
    //debugger;
    loginUser(userName: string, password: string){
        this.currentUser = {
            id: 1,
            userName: userName,
            firstName: 'Bipon',
            lastName: 'Biswas'
        }
    }
    isAuthenticated(){
        return !this.currentUser;
    }
    updateCurrentUser(firstName:string, lastName: string){
        this.currentUser.firstName = firstName
        this.currentUser.lastName = lastName
    }

}</code></pre>



<p>app.module.ts </p>



<pre class="wp-block-code"><code>import { ProfileComponent } from './profile.component';
import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router'
import { userRoutes } from './user.routes'
import { LoginComponent } from './login.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'

@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        ReactiveFormsModule,
        RouterModule.forChild(userRoutes)
    ],
    declarations: [
        ProfileComponent,
        LoginComponent
    ],
    providers: [

    ]

})
export class UserModule{

}</code></pre><p>The post <a href="https://biponnotes.iglyphic.com/creating-your-first-reactive-form/">Creating Your First Reactive Form</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://biponnotes.iglyphic.com/creating-your-first-reactive-form/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">312</post-id>	</item>
	</channel>
</rss>
