Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AngularFireAuth } from 'angularfire2/auth';
- import { Injectable } from '@angular/core';
- import * as firebase from 'firebase';
- import { Observable } from 'rxjs/Observable';
- @Injectable()
- export class AuthService {
- user$: Observable<firebase.User>;
- constructor(private afAuth: AngularFireAuth) {
- this.user$ = afAuth.authState;
- }
- getUser() {
- console.log(this.user$);
- }
- loginWithEmailAndPassword(email, password) {
- this.afAuth.auth.signInWithEmailAndPassword(email, password);
- }
- loginWithGoogle() {
- this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider());
- }
- logOut() {
- this.afAuth.auth.signOut();
- }
- }
- import { Observable } from 'rxjs/Observable';
- import { AuthService } from './auth.service';
- import { Injectable } from '@angular/core';
- import { AngularFireDatabase } from 'angularfire2/database';
- @Injectable()
- export class MyListService {
- myFokos: Observable<any[]>;
- constructor(auth: AuthService, database: AngularFireDatabase) {
- auth.user$.subscribe(user => {
- console.log('User is logged in. UID: ' + user.uid);
- this.myFokos = database.list('users/' + user.uid + '/glossaries').snapshotChanges();
- });
- }
- }
- import { AuthService } from './../../services/auth.service';
- import { MyListService } from './../../services/my-list.service';
- import { Component, OnInit } from '@angular/core';
- @Component({
- selector: 'app-my-fokos',
- templateUrl: './my-fokos.component.html',
- styleUrls: ['./my-fokos.component.css']
- })
- export class MyFokosComponent implements OnInit {
- constructor(public myListService: MyListService, public auth: AuthService) { }
- ngOnInit() {
- this.auth.user$.subscribe(x => {
- console.log(x);
- });
- }
- }
- MyFokosComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'subscribe' of undefined
- at MyFokosComponent.ngOnInit (my-fokos.component.ts:15)
- at checkAndUpdateDirectiveInline (core.js:12364)
- at checkAndUpdateNodeInline (core.js:13888)
- at checkAndUpdateNode (core.js:13831)
- at debugCheckAndUpdateNode (core.js:14724)
- at debugCheckDirectivesFn (core.js:14665)
- at Object.eval [as updateDirectives] (MyFokosComponent_Host.ngfactory.js? [sm]:1)
- at Object.debugUpdateDirectives [as updateDirectives] (core.js:14650)
- at checkAndUpdateView (core.js:13797)
- at callViewAction (core.js:14148)
- *ngFor="let foko of myListService.myFokos | async"
Add Comment
Please, Sign In to add comment