地图运算符不适用于 AngularFireAuth Observable
map operator not working on AngularFireAuth Observable
我正在使用 Angular 和 firebase(使用 AngularFire2)构建一个应用程序。当尝试在任何 firebase 可观察对象(FirebaseAuthObservable、FirebaseListObservable)上使用 .map 运算符时,出现错误
[s] Supplied parameters do not match any signature of call target. (property) AngularFire.auth: AngularFireAuth
这是我的代码
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))
}
}
我在这里遗漏了什么吗?
编辑**
我试过只创建一个新的 Observable 并在其上使用 map 运算符,但这也不起作用。
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)
}
}
我得到的错误是:
[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
您没有导入 AngularFireAuth(以前称为 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))
}
}
我正在使用 Angular 和 firebase(使用 AngularFire2)构建一个应用程序。当尝试在任何 firebase 可观察对象(FirebaseAuthObservable、FirebaseListObservable)上使用 .map 运算符时,出现错误
[s] Supplied parameters do not match any signature of call target. (property) AngularFire.auth: AngularFireAuth
这是我的代码
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))
}
}
我在这里遗漏了什么吗?
编辑**
我试过只创建一个新的 Observable 并在其上使用 map 运算符,但这也不起作用。
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)
}
}
我得到的错误是:
[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
您没有导入 AngularFireAuth(以前称为 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))
}
}