Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component} from '@angular/core';
- import {ControlGroup, Control, Validators, FormBuilder} from '@angular/common'
- import {UsernameValidators} from './usernameValidators'
- @Component({
- selector: 'signup',
- templateUrl: 'signup-component.html'
- })
- export class SignupComponent{
- form: ControlGroup;
- constructor(fb: FormBuilder){
- this.form = fb.group({
- username:['', Validators.compose([
- Validators.required, UsernameValidators.cannotContainSpace
- ])],
- password: ['', Validators.required]
- })
- }
- }
- import {Control} from '@angular/common'
- export class UsernameValidators{
- static shouldBeUnique(control: Control){
- return new Promise((resolve, reject) => {
- setTimeout(function(){
- if(control.value == "andy")
- resolve({shouldBeUnique: true});
- else
- resolve(null);
- }, 1000);
- });
- }
- static cannotContainSpace(control: Control){
- if (control.value.indexOf(' ') >= 0)
- return {cannotContainSpace: true};
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement