【发布时间】:2020-08-27 14:06:54
【问题描述】:
我想在 firebase 中更新用户的 displayName 和/或照片 URL。我正在使用角度。我有一个处理身份验证内容的服务,它适用于登录/注册/等。我创建了另一个服务来处理用户数据(UserService)。但是,当我尝试调用 updateProfile 函数时,出现以下编译错误。 docs 显示通过用户对象调用的函数,但它没有解释该用户对象是什么。
错误
error TS2339: Property 'updateProfile' does not exist on type 'AngularFireAuth'
我已经尝试了多种方法 - 包括下面的一种方法,它会产生上述错误,并使用 currentUser 函数创建一个用户对象,然后尝试在该对象上调用该方法。似乎没有任何效果。
import { Injectable, NgZone } from '@angular/core';
import { User } from "app/main/services/users";
import { auth } from 'firebase/app';
import { AngularFireAuth } from "@angular/fire/auth";
import { AngularFirestore, AngularFirestoreDocument } from '@angular/fire/firestore';
import { Router } from "@angular/router";
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(
public afs: AngularFirestore, // Inject Firestore service
public afAuth: AngularFireAuth, // Inject Firebase auth service
public router: Router,
public ngZone: NgZone // NgZone service to remove outside scope warning
) { }
/**
* Update the image or username
*/
UpdateProfile( displayName ) {
console.log('In Update profile');
return this.afAuth.updateProfile({
displayName: displayName,
photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then((result) => {
console.log('Did the update profile');
}, function(error){
});
}
}
【问题讨论】:
标签: javascript angular firebase firebase-authentication angularfire2