0

I can't seem to figure out why my db object is being returned as undefined, I unpack it with a .subscribe in the ts file, but can't access any of its values. I think I must be missing something to do with using .child?

I call this to populate the data

test() {
    this.assessment.first = "test";
    this.assessment.second = "test";
    this.assessment.third = "test";
    this.assessment.education = 1;
    this.assessment.civic = 1;
    this.assessment.employment = 1;
    this.assessment.health = 1;
    this.assessment.housing = 1;
    this.assessment.social = 1;
    this.visionService.createAssessmentItem(this.assessment)
    console.log(this.assessment);
  }

then in the same ts file

assessment;

  constructor(private visionService: VisionService,
              public auth: AuthService) { }

  ngOnInit() {
    //this.assessments = this.visionService.getAssessment();

    this.assessment = this.visionService.getAssessment().subscribe(a => {
      this.assessment = a
    });
    console.log(this.auth.currentUser.uid);
    console.log(this.assessment);
  }

I print the user id to make sure that they exist and infact have data.

my Service

 getAssessment(): FirebaseObjectObservable<any> {
    const path = `/assessments/${this.userId}`
    console.log(this.userId) // make sure it matches.
    return this.db.object(path);
  }

and in the db

0yUcmxq0Tig9TW3mCJWwGOo5c8l1
 -KqMjDGfbSb5qS2o0MIL
 civic: 1
 education: 1
 employment: 1
 first: "test"
 health: 1
 housing: 1
 second: "test"
 social: 1
 third: "test"

Can someone please show and explain the best way to do this? It honestly can't be that difficult and I feel I'm missing something critical here.

theHussle
  • 321
  • 3
  • 17
  • Possible duplicate of [How do I return the response from an Observable/http/async call in angular2?](https://stackoverflow.com/questions/43055706/how-do-i-return-the-response-from-an-observable-http-async-call-in-angular2) – AT82 Jul 31 '17 at 09:09
  • That's not using Angularfire 2 is it? – theHussle Jul 31 '17 at 09:15
  • I'll take a good look and see if it can solve it none the less – theHussle Jul 31 '17 at 09:16

0 Answers0