gpt4 book ai didi

angular - map 运算符不适用于 AngularFireAuth Observable

转载 作者:太空狗 更新时间:2023-10-29 18:31:17 25 4
gpt4 key购买 nike

我正在使用 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 - map 运算符不适用于 AngularFireAuth Observable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43750718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com