logo
down
shadow

Accessing data returned by Promise.all


Accessing data returned by Promise.all

By : Shreyansh Mridul
Date : November 19 2020, 03:01 PM
will be helpful for those in need Your issue is within the service. There are a couple things going on here.
http.get returns an Observable. This must be subscribed to or converted to a Promise. Promise.all() will work normally for promises but will just pass in what it was given for anything else(like an Observable or variables etc.)
code :
public getProductCategoryData() {
   return Promise.all([this.http.get(this.specialValueUrl).toPromise(), 
    this.http.get(this.applianceBrandUrl).toPromise()])

}
private getProductCategoryData() {
this.productCategoryService.getProductCategoryData()
  .then(productCategoryData => {
      this.specialValues = productCategoryData[0];
      this.applianceBrands = productCategoryData[1];

      console.log('productCategory.Data = ', productCategoryData) //has data
      console.log('this.specialValues = ', this.specialValues) //undefined
      console.log('this.applianceBrands = ', this.applianceBrands) //undefined

    });
  }


Share : facebook icon twitter icon
Accessing object in returned promise using fetch w/ react js

Accessing object in returned promise using fetch w/ react js


By : Rakesh nayak
Date : March 29 2020, 07:55 AM
it helps some times response.json() returns a promise, so you also need to handle it appropriately, eg:
code :
.then(function(response) {
    return response.json();
})
.then(function(parsedData) {
    // data here
})
Accessing the result of a returned promise

Accessing the result of a returned promise


By : DarrenMc
Date : March 29 2020, 07:55 AM
To fix the issue you can do fetch(...) returns a promise, and response.json() returns another promise.
The returned value is not an array but a promise of an array. It should be:
code :
getRemoteData().then(result => {
  console.log(result);
});
(async () => {
    const result = await getRemoteData();
    console.log(result);
})();
Accessing the value returned by .then() promise

Accessing the value returned by .then() promise


By : user3045713
Date : March 29 2020, 07:55 AM
Hope this helps You are assigning a promise to the variable tableCount. That's the reason why console.log is logging a promise. To access the resolved value of the promise you can try the following:
code :
conn
 .then((client) => {
   const promise = new Promise((resolve, reject) => {
    client.query(query1, (err, result) => {
     if(err) {
      reject(err);
     }
     resolve(result[0].cnt);
    })
   });
   return promise;
 })
 .then((tableCount) => {
   console.log(tableCount);
 })
accessing returned promise object array values

accessing returned promise object array values


By : user69789
Date : March 29 2020, 07:55 AM
this will help The provider function returns an Angular Promise object. It does not directly return your data. Instead you provide the Promise with a function to call once the Promise has resolved.
You should instead do:
In ES6 JavaScript, why is the promise returned by the fulfillment handler of then() not the same as the promise returned

In ES6 JavaScript, why is the promise returned by the fulfillment handler of then() not the same as the promise returned


By : Thanasis Gazos
Date : September 20 2020, 11:00 PM
will help you This is because those promises are created at a different time:
new Promise(....).then() returns a promise that is immediately available (as lala), while the callback passed to that then method will only be executed when new Promise(....) resolves, i.e. potentially much later.
Related Posts Related Posts :
  • Angular 4 Force navigate with refresh
  • Query dom element's properties Angular 4
  • Angular Material Dialog return value
  • Accessing HTTP Error Response Body from HttpInterceptor in Angular
  • Resolve Adal Token for Http Interceptor
  • Is it possible to change namespace name in @nrwl/nx?
  • Angular 4 Router: Getting redirected inside children's first route
  • Uncaught Error: Template parse error There is not such directive with exportAs
  • How can I use @HostListener('window:beforeunload') to call a method?
  • Is it possible to get the type from a generic, given as parameter
  • Ionic 3 - Preventing browser close
  • How to set the color of an icon in Angular Material?
  • how do i handle POST response
  • constructor being called duplicate in *ngFor due to @ViewChild
  • Angular4 OAuth2 IdentityServer4
  • ERROR TypeError: Cannot read property 'name' of undefined
  • Angular4 http get with URL parameter
  • What is the difference between fakeAsync's tick() and done() in angular2 testing?
  • How to push in service without losing previous data?
  • How to make custom arrow mark in agm-map?
  • Upload File in Angular 4 using FormData works in Local but not on Azure App Service
  • How to automatically deploy a Laravel app with embedded Angular to Heroku
  • Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'
  • use angular-cli project with visual studio asp.net empty web app?
  • How to load different templates for the same component?
  • Creating Angular4 'Loading' Screen: ExpressionChangedAfterItHasBeenCheckedError
  • How to pass a array value as color in Angular 4
  • Coerce the HttpResponse into an item of the specified type, complete with custom methods
  • Angular/rxjs: Why don't I have to import toPromise anymore?
  • Angular 2 @Input not works for router outlet
  • Nested Model - Angular 2
  • Supress duplicate error in aot compiler
  • Angular2 ExpressionChangedAfterItHasBeenCheckedError
  • Consuming my promise inside my Angular component
  • Despite error cannot read property length of null, the code works
  • How to add background image with ngStyle?
  • Property X doesn't exist on type Y[]
  • Ionic Headers Failing to set through http.post
  • Angular 4 routing/state problems
  • Angular 2 Dashboard application web api call at initialization
  • ngrx/store:subscribe works fine but async in template gives [object Object]
  • Angular2 - how to mix custom and declared arguments in constructor
  • Implementing Geolocation from @ionic-native/geolocation
  • Angular - Test library before publish
  • AoT Compilation Failed - no such file or directory, lstat 'tsconfig-aot.json'
  • Docker container from Angular4 app : "-p" : executable file not found in $PATH
  • Invalid container name
  • Angular - NgStyle fall back image
  • Angular Observable not updating when I subscribe.
  • Angular mat-checkbox getElementById
  • Angular 4 Injecting route in the APP_INITIALIZER
  • Error: EACCES: Error: EACCES: permission denied, open '/Users/emilio/.ionic/daemon.log' at Error (native)
  • selected value in dropdown list does not work Angular
  • how to smooth scroll down to element on page load angular 4?
  • AngularFire update breaks the app
  • experimentalDecorators Warning on ts lint
  • Dexie - Check if a record exists and initialize it if not present
  • How should I use BehaviorSubject class from a Service in the HTML Template of a Component in Angular 4?
  • How to make ngx-bootstrap datepicker be able to select and display only month and year?
  • What is wrong with this Angular form that makes it reset selected values in the UI unexpectedly?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org