Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <form noValidate (ngSubmit)="onSubmit(login)" [formGroup]="login">
  2. Username:<br> <input type="text" formControlName="username"><br>
  3. <div class="error"
  4. *ngIf="login.get('username').hasError('required') && login.get('username').touched">
  5. Username required</div>
  6.  
  7. Password:<br> <input type="password" formControlName="password"><br>
  8. <div class="error"
  9. *ngIf="login.get('password').hasError('required') && login.get('password').touched">
  10. Password required</div>
  11.  
  12. <br> <input type="submit" value="Login" [disabled]="login.invalid">
  13.  
  14. export class LoginComponent implements OnInit {
  15. login: FormGroup;
  16. response: ResponseInterface;
  17.  
  18. constructor() {
  19. }
  20.  
  21. ngOnInit() {
  22. this.login = new FormGroup({
  23. username: new FormControl('', [Validators.required, Validators.required]),
  24. password: new FormControl('', [Validators.required, Validators.required])});
  25. }
  26.  
  27. onSubmit({ value, valid }: { value: LoginInterface, valid: boolean }) {
  28. console.log(value, valid);
  29. }
  30. }
  31.  
  32. export interface LoginInterface {
  33. username: String;
  34. password: String;
  35. }
  36.  
  37. export class DropdownosComponent {
  38. private list = [
  39. { id: 1, name: 'ONE' },
  40. { id: 2, name: 'TWO' },
  41. { id: 3, name: 'THREE'}
  42. ];
  43. private current: number = 1;
  44.  
  45. private setCurrent(id: number): void {
  46. this.current = id;
  47. }
  48. public getCurrent(): string {
  49. return this.list.find((item: any) => item.id == this.current).name;
  50. }
  51. }
  52.  
  53. <select #select [(ngModel)]="current"
  54. (change)="setCurrent(select.value)">
  55. <option *ngFor="let item of list" [value]="item.id">{{item.name}}</option>
  56. </select>
  57.  
  58. export interface LoginInterface {
  59. username: String;
  60. password: String;
  61. dropdown: String;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement