在firebase中显示离子3中的用户数据

时间:2018-04-20 15:03:54

标签: node.js angular firebase ionic3 angularfire

我的.val()属性有问题。

this.userProfile = profile.val(); <<<<这是问题



import { Component, OnInit } from "@angular/core";
import { AuthService } from "../../providers/auth/auth.service";
import { DataService } from "../../providers/data/data.service";
import { User } from 'firebase/app'
import { Profile } from "../../models/profile/profile.interface";
import jQuery from "jquery";
import { getQueryValue } from "@angular/core/src/view/query";
import { USER_LIST } from "../../mocks/profiles/profile";

@Component({
    selector: 'app-profile-view',
    templateUrl: 'profile-view.component.html'
})

export class ProfileViewComponent implements OnInit {

    userProfile: Profile;
     
    
    ngOnInit(): void {
           this.auth.getAuthenticatedUser().subscribe((user: User) => {
                this.data.getProfile(user).valueChanges().subscribe(profile => {
                  this.userProfile = <Profile>profile.val(); <<<< here is the problem>>>>>>   

            })
        })
   
&#13;
&#13;
&#13;

,这是个人资料界面

&#13;
&#13;
export interface Profile {
firstName: string;
lastName: string;
avatar: string;
email: string;
dateOfBirth: Date;


}
&#13;
&#13;
&#13;

,这是来自/ mocks的profile.ts

&#13;
&#13;
import { Profile } from '../../models/profile/profile.interface';

const userList: Profile[] = [
{firstName: 'ahmed', lastName: 'hallaq', email: 'a.m.hq@hotmail.com', avatar: 'assets/img/avatar.png', dateOfBirth: new Date() },
{firstName: 'ahmed', lastName: 'hallaq', email: 'a.m.hq@hotmail.com', avatar: 'assets/img/avatar.png', dateOfBirth: new Date() },
{firstName: 'ahmed', lastName: 'hallaq', email: 'a.m.hq@hotmail.com', avatar: 'assets/img/avatar.png', dateOfBirth: new Date() },
{firstName: 'ahmed', lastName: 'hallaq', email: 'a.m.hq@hotmail.com', avatar: 'assets/img/avatar.png', dateOfBirth: new Date() },


];

export const USER_LIST = userList;
&#13;
&#13;
&#13;

这个来自html文件我想让它显示数据库中的第一个名字

&#13;
&#13;
<ion-item>
            <ion-label floating>First Name</ion-label>
            <ion-input [value]="userProfile.firstNAme" [readonly]="true"></ion-input>
        </ion-item>
&#13;
&#13;
&#13;

当我做离子发球时,它给了我[[profile.val不是一个功能]]

1 个答案:

答案 0 :(得分:0)

你为什么使用.val()?它不能是配置文件的功能,您甚至可以显示Profile接口,它没有val()函数。

你能这样设置吗?什么是订阅中个人资料的价值?

ngOnInit(): void {
    this.auth.getAuthenticatedUser().subscribe((user: User) => {
        this.data.getProfile(user)
            .valueChanges()
            .subscribe((profile: Profile) => {
                 this.userProfile = profile; 
                 // What is the value of profile? Console log it? Debug it?
    })
})