Cita:
mi componete login es el siguienteTypeError: Cannot read property 'navigate' of undefined
at Object.next (login.component.ts:26)
at Object.next (login.component.ts:26)
Código:
mi routing es el siguiente:import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { AngularFireAuth } from 'angularfire2/auth'; import * as firebase from 'firebase/app'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) export class LoginComponent implements OnInit { loginForm: FormGroup; user: Observable<firebase.User>; returnUrl: string; constructor(public afAuth: AngularFireAuth, private router: Router) { this.user = afAuth.authState; } ngOnInit() { this.afAuth.auth.onAuthStateChanged(function(user){ if (user) { this.router.navigate(['/home']); } }); this.loginForm = new FormGroup({ 'email': new FormControl('', Validators.required), 'password': new FormControl('', Validators.required) }) } login(){ this.afAuth.auth.signInWithEmailAndPassword(this.loginForm.get('email').value, this.loginForm.get('password').value).then(function(user){ this.router.navigate(['/home']); }, function(error) { console.log("Error Login: ", error); }); } }
Código:
import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { LoginComponent } from './login/login.component'; import { HomeComponent } from './home/home.component'; const routes: Routes = [ { path: '', redirectTo: 'login', pathMatch: 'full' }, { path: 'login', component: LoginComponent }, { path: 'home', component: HomeComponent} ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule], providers: [] }) export class L3RoutingModule { }