Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import {Component} from '@angular/core';
  2. import {ControlGroup, Control, Validators, FormBuilder} from '@angular/common'
  3. import {UsernameValidators} from './usernameValidators'
  4.  
  5. @Component({
  6. selector: 'signup',
  7. templateUrl: 'signup-component.html'
  8.  
  9. })
  10.  
  11.  
  12. export class SignupComponent{
  13. form: ControlGroup;
  14. constructor(fb: FormBuilder){
  15. this.form = fb.group({
  16. username:['', Validators.compose([
  17. Validators.required, UsernameValidators.cannotContainSpace
  18. ])],
  19. password: ['', Validators.required]
  20.  
  21.  
  22. })
  23.  
  24. }
  25. }
  26.  
  27. import {Control} from '@angular/common'
  28.  
  29.  
  30. export class UsernameValidators{
  31.  
  32. static shouldBeUnique(control: Control){
  33. return new Promise((resolve, reject) => {
  34. setTimeout(function(){
  35. if(control.value == "andy")
  36. resolve({shouldBeUnique: true});
  37. else
  38. resolve(null);
  39. }, 1000);
  40.  
  41. });
  42.  
  43. }
  44.  
  45.  
  46. static cannotContainSpace(control: Control){
  47. if (control.value.indexOf(' ') >= 0)
  48. return {cannotContainSpace: true};
  49.  
  50. return null;
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement