映射运算符不处理AngularFireAuth Observable
我正在构建一个带有AngularFire2和firebase的应用程序。当尝试在任何firebase可观察对象(FirebaseAuthObservable,FirebaseListObservable)上使用.map操作符时,我得到一个错误映射运算符不处理AngularFireAuth Observable,angular,firebase,firebase-authentication,rxjs,angularfire2,Angular,Firebase,Firebase Authentication,Rxjs,Angularfire2,我正在构建一个带有AngularFire2和firebase的应用程序。当尝试在任何firebase可观察对象(FirebaseAuthObservable,FirebaseListObservable)上使用.map操作符时,我得到一个错误 [s] Supplied parameters do not match any signature of call target. (property) AngularFire.auth: AngularFireAuth 这是我的密码 import {
[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))
}
}
这里有我遗漏的东西吗
编辑**
我试着创建一个新的可观察对象,并在其上使用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)
}
}
从'@angular/core'导入{Component};
从“rxjs/Observable”导入{Observable};
导入'rxjs/add/operator/map';
@组成部分({
选择器:'应用程序根',
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent{
构造函数(){
设x:Observable=Observable.create(Observable=>{
下一步(“测试”);
})
x、 map(str=>str+“”);//此行出错(见下文)
}
}
我得到的错误是:
[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
[ts]提供的参数与调用目标的任何签名都不匹配。
将给定的项目函数应用于源发出的每个值
可观察的,并将结果值作为可观察值发出。
类似于Array.prototype.map(),
它通过转换函数传递每个源值以获得
相应的输出值。
与众所周知的Array.prototype.map函数类似,此运算符
将投影应用于每个值,并在输出中发射该投影
可见的。
@示例将每次单击映射到该单击的clientX位置
var clicks=Rx.Observable.fromEvent(文档“click”);
var positions=clicks.map(ev=>ev.clientX);
positions.subscribe(x=>console.log(x));
@请参阅{@link mapTo}
@参见{@link-pull}
@返回{Observable}从源发出值的可观察对象
由给定的项目功能转换的可观察性。
@方法图
@可观察所有者
您没有导入AngularFireAuth(以前的FirebaseAuth)
我完全复制了这一点,但我得到“[ts]提供的参数与调用目标的任何签名都不匹配。”我导入了rxjs/add/operator/mapI。我认为这个问题可能比Firebase更广泛。查看我的新编辑。我创建了一个新的Observable,并尝试将其映射为更多错误。您能创建一个最小的复制吗?上面引用的文件位于src/app/app.component.t中,无法复制。步骤:(1)
纱线安装
(2)x.map(str=>str+).subscribe(console.log)代码>(3)ng serve
(4)在控制台localhost:4200
hmmm处打印test
。我使用的是VS代码。也许有什么问题?
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))
}
}