Map operator not working on AngularFireAuth Observable

I am creating an app with Angular and firebase (using AngularFire2). When trying to use the .map operator on any of the firebase observables (FirebaseAuthObservable, FirebaseListObservable) I get the error

[s] Supplied parameters do not match any signature of call target. (property) AngularFire.auth: AngularFireAuth

      

Here is my code

import { Component, OnInit } from '@angular/core';
import { AngularFire } from 'angularfire2'
import { Router, ActivatedRoute } from '@angular/router';
import {Observable } from 'rxjs/Observable';
import 'rxjs/Rx';

@Component({
  selector: 'app-edit-objective',
  templateUrl: './edit-objective.component.html',
  styleUrls: ['./edit-objective.component.css']
})
export class EditObjectiveComponent implements OnInit {

    constructor(private af: AngularFire, private route: ActivatedRoute, public router: Router) { }

    ngOnInit() {
        this.af.auth
         .map((x) => {})
         .subscribe(y => console.log(y))
    }
}

      

Am I missing something here?

EDIT **

I've tried just creating a new Observable and using the map operator on it, and also doesn't work.

import { Component } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    let x: Observable<string> = Observable.create(observer => {
      observer.next('test');
    })
    x.map(str => str + " ");  //Error on this line (see below)
  }
}

      

The error I am getting:

[ts] Supplied parameters do not match any signature of call target.
pplies a given project function to each value emitted by the source
Observable, and emits the resulting values as an Observable.

<span class="informal">Like Array.prototype.map(),
it passes each source value through a transformation function to get
corresponding output values.</span>

<img src="./img/map.png" width="100%">

Similar to the well known Array.prototype.map function, this operator
applies a projection to each value and emits that projection in the output
Observable.

@example <caption>Map every click to the clientX position of that click</caption>
var clicks = Rx.Observable.fromEvent(document, 'click');
var positions = clicks.map(ev => ev.clientX);
positions.subscribe(x => console.log(x));

@see {@link mapTo}
@see {@link pluck}

@return {Observable<R>} An Observable that emits the values from the source
Observable transformed by the given project function.
@method map
@owner Observable

      

+3


source to share


1 answer


You haven't imported AngularFireAuth (formerly FirebaseAuth)



import { AngularFireAuth } from 'angularfire2/auth';

...

export class EditObjectiveComponent implements OnInit {

  constructor(private afAuth: AngularFireAuth) { }

  ngOnInit() {
    this.afAuth.authState
      .map(x => x.uid)
      .subscribe(x => console.log(x))
  }

}

      

+2


source







All Articles