17.10.2018 Views

Angular

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A password is required<br />

A password needs to have at least 4<br />

characterss<br />

<br />

<br />

Register<br />

<br />

Section 24.3: Simple Password Change Form with Multi<br />

Control Validation<br />

The below examples use the new form API introduced in RC3.<br />

pw-change.template.html<br />

<br />

Current Password<br />

<br />

New Password<br />

<br />

<br />

New password can't be the same as current password.<br />

<br />

Confirm new password<br />

<br />

<br />

The confirmation does not match.<br />

<br />

Submit<br />

<br />

pw-change.component.ts<br />

import {Component} from '@angular/core'<br />

import {REACTIVE_FORM_DIRECTIVES, FormBuilder, AbstractControl, FormGroup,<br />

Validators} from '@angular/forms'<br />

import {PWChangeValidators} from './pw-validators'<br />

@Component({<br />

moduleId: module.id<br />

selector: 'pw-change-form',<br />

templateUrl: `./pw-change.template.html`,<br />

directives: [REACTIVE_FORM_DIRECTIVES]<br />

})<br />

export class PWChangeFormComponent {<br />

pwChangeForm: FormGroup;<br />

// Properties that store paths to FormControls makes our template less verbose<br />

current: AbstractControl;<br />

newPW: AbstractControl;<br />

confirm: AbstractControl;<br />

constructor(private fb: FormBuilder) { }<br />

ngOnInit() {<br />

this.pwChangeForm = this.fb.group({<br />

GoalKicker.com – <strong>Angular</strong> 2 Notes for Professionals 105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!