user6004361
user6004361

Reputation:

how can I access the __zone_symbol__value on the ZoneAwarePromise in Angular 2

I am receiving a ZoneAwarePromise and when I logged it to the console I found that it contains a __zone_symbol__value. I was wondering if it's possible to set a variable equal to that __zone_symbol__value?

Upvotes: 19

Views: 66781

Answers (9)

fabricio
fabricio

Reputation: 1393

As you know storage.get returns a promise, not the value. You'll need to unwrap the promise in a .then

storage.get('key')
.then( res => console.log(res));

Upvotes: 4

suraj garla
suraj garla

Reputation: 318

you are receiving this __zone_symbol__value, because you have mistakenly including your async validator returning promise in the sync validators list, try changing the posiiton of your validator, it worked for me.

Upvotes: 3

Feng Zhang
Feng Zhang

Reputation: 1968

the caller of the async method needs to be async as well.

Upvotes: 2

Amar Amrouz
Amar Amrouz

Reputation: 11

async yourFunction(){
    const Ref0 = firebase.firestore().collection("your_collection").doc(doc.id)

    const Ref1 = appointmentsRef.where('val1', '==',condition1).get();
    const Ref2 = appointmentsRef.where("val2", "!=", condition2).get()

    const [snapshot_val1, snapshot_val2] = await Promise.all([Ref1, Ref2]);

    
    const val1_Array = snapshot_val1.docs;
    const val2_Array = snapshot_val2.docs;

    const globale_val_Array = val1_Array .concat(val2_Array );

    return globale_val_Array ;
  }



/*Call you function*/
this.checkCurrentAppointment().then(docSnapshot=> {
      docSnapshot.forEach(doc=> {
          console.log("Your data with multiple code query:", doc.data());
      });
    });

Upvotes: 0

Grant
Grant

Reputation: 6329

I usually declare my observables with a $ symbol notation to keep track, for example:

this.profile$: any;
this.profile: any;

this.profile$ = navParams.get('profile');

Utilising the then() method to return the promise, I populate a variable free of the $ notation

const self = this;

this.profile$.then(val => self.profile = val);

I set a constant of self retaining the this global object otherwise the promise itself is referred to, rather than the parent.

Hope this helps someone simplify the process.

Upvotes: 0

littgle
littgle

Reputation: 89

async onEditConfirm(event): Promise<void> {
    //async/await the method returning your => __zone_symbol__value
    await event.confirm.resolve(event.newData);
    //at this point your async operation will have completed
    this.onSave();
}

Upvotes: 0

luisbg
luisbg

Reputation: 574

in your view you can access with pipe async

( variable | async)?.field

Upvotes: 2

jsaddwater
jsaddwater

Reputation: 1829

I'm doing it like this:

  ngOnInit() {    
    console.log(" Ticket initialized");
    this.getBranchTickets().then(data => console.log(data));
  }

  getBranchTickets() {
   return this.ticketService.getBranchTickets().$promise;
  }

Upvotes: 19

Make sure that you are not returning an asynchronous object (Observable or Promise for example) instead of primitive, Object, Array e etc

Upvotes: -2

Related Questions