0

I want to display my database data into ionic view. here detail data in my database:

{firstName: "John", lastName: "Doe", username: "jhondoe"}

my code in page controller:

import { AngularFireDatabase,  FirebaseObjectObservable  } from 'angularfire2/database';

profile : FirebaseObjectObservable<Profile>;


this.afAuth.authState.subscribe(data => {
  if(data.email && data.uid){   
    this.afDatabase.object(`profile/${data.uid}`).valueChanges().subscribe(profile => {   
      this.profile = profile;
      console.log(profile);
    });

});

view page:

<ion-content padding>

  <p>Username: {{ profile?.username | async }}</p>
  <p>First Name: {{ profile?.firstName  | async }}</p>
  <p>Last Name: {{ profile?.LastName  | async }}</p>

</ion-content>

but it not work, and display error:

InvalidPipeArgument: 'John' for pipe 'AsyncPipe'

1 Answer 1

1

profile is not a promise/observable since you are setting data after subscription here:

 this.afDatabase.object(`profile/${data.uid}`).valueChanges().subscribe(profile => {   
      this.profile = profile;
      console.log(profile);
    });

Either declare profile as a regular object and remove async:

 profile : Profile;

Html:

<p>Username: {{ profile?.username }}</p>
<p>First Name: {{ profile?.firstName}}</p>
<p>Last Name: {{ profile?.LastName}}</p>

OR.

declare as an observable and do not subscribe in ts.

 profile : Observable<Profile>;



this.profile = this.afDatabase.object(`profile/${data.uid}`).valueChanges();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.