mock-login.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Component, OnInit } from '@angular/core';
  2. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  3. import { first } from 'rxjs/operators';
  4. import {NavController} from "ionic-angular";
  5. import { HomePage } from "../home/home";
  6. @Component({templateUrl: 'mock-login.html'})
  7. export class MockLoginPage implements OnInit {
  8. loginForm: FormGroup;
  9. loading = false;
  10. submitted = false;
  11. returnUrl: string;
  12. constructor(
  13. private formBuilder: FormBuilder,
  14. public navCtrl: NavController
  15. ) {
  16. }
  17. ngOnInit() {
  18. this.loginForm = this.formBuilder.group({
  19. username: ['', Validators.required],
  20. password: ['', Validators.required]
  21. });
  22. }
  23. // convenience getter for easy access to form fields
  24. get f() { return this.loginForm.controls; }
  25. onSubmit() {
  26. this.submitted = true;
  27. // stop here if form is invalid
  28. if (this.loginForm.invalid) {
  29. return;
  30. }
  31. else{
  32. console.log('loginform control',this.loginForm);
  33. if(this.loginForm.value['username'] == 'test' && this.loginForm.value['password'] == 'test' )
  34. this.navCtrl.setRoot(HomePage);
  35. }
  36. }
  37. }