Added routing after login/registering

This commit is contained in:
piratefinn 2017-05-10 16:26:57 +01:00
parent b6ab962f36
commit b888fb0193
2 changed files with 10 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { Validators, FormBuilder, FormGroup } from '@angular/forms'; import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { Http, Response } from '@angular/http'; import { Http, Response } from '@angular/http';
import { ApiService } from '../providers/api-service'; import { ApiService } from '../providers/api-service';
import {Router } from '@angular/router';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
@Component({ @Component({
@ -15,6 +16,7 @@ export class LoginComponent {
constructor( constructor(
private http: Http, private http: Http,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router,
private api: ApiService private api: ApiService
) { ) {
this.api.getAgeRanges() this.api.getAgeRanges()
@ -33,11 +35,12 @@ export class LoginComponent {
onSubmit() { onSubmit() {
console.log(this.signin.value); console.log(this.signin.value);
this.peopleService this.api
.register(this.signin.value) .register(this.signin.value)
.subscribe( .subscribe(
result => { result => {
console.log( logged in! ); console.log('logged in!');
this.router.navigate(['/dashboard'])
}, },
error => { error => {
console.log( error._body ); console.log( error._body );

View file

@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { Validators, FormBuilder, FormGroup } from '@angular/forms'; import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { Http, Response } from '@angular/http'; import { Http, Response } from '@angular/http';
import { ApiService } from '../providers/api-service'; import { ApiService } from '../providers/api-service';
import {Router } from '@angular/router';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
@Component({ @Component({
@ -15,6 +16,7 @@ export class RegisterComponent {
constructor( constructor(
private http: Http, private http: Http,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router,
private api: ApiService private api: ApiService
) { ) {
this.api.getAgeRanges() this.api.getAgeRanges()
@ -38,11 +40,12 @@ export class RegisterComponent {
onSubmit() { onSubmit() {
console.log(this.signup.value); console.log(this.signup.value);
this.peopleService this.api
.register(this.signup.value) .register(this.signup.value)
.subscribe( .subscribe(
result => { result => {
console.log( registered! ); console.log('registered!');
this.router.navigate(['/dashboard']);
}, },
error => { error => {
console.log( error._body ); console.log( error._body );