The promise object is displayed instead of the actual data retrieved from the API call

I am currently working on fetching data from an API and showcasing the name of the returned data on the front end.

This function successfully retrieves the data through an API call:

async function retrieveData(url){
var _data;
 let response = await fetch(url);
 let data = await response.json();  
 _data = [data.name, data.id];
 console.log(_data);
 return _data[0];

After logging to the console, I can see the desired outputhttps://i.sstatic.net/TzzGJ.png

However, when attempting to display it on the front end like this:

 options = retrieveData('https://api.opensea.io/api/v1/asset/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb/1/');

I use {{options}} to temporarily showcase the fetched data until further development.

The displayed result is as follows:

https://i.sstatic.net/ITy9Y.png

Rather than displaying [cryptopunk #1, 158831], it shows [object Promise]. Any insights on what might be going wrong?

Please note that the 'options = retrieveData()' is within the class and the async function appears above the @component tag.

Answer №1

Have you given this a try?

retrieveData('https://api.opensea.io/api/v1/asset/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb/1/').then(data=>{
console.log(data);
})

It appears to be functioning correctly

async function retrieveData(url){
  var _data;
  let response = await fetch(url);
  console.log(response);
  return response;
 }
 
 retrieveData('https://jsonplaceholder.typicode.com/todos/1').then(option=>{
 console.log(option)
 })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

UI grid sorting and filtering for custom cell template

In my UI-grid, there is a linq template cell. Here is the code from the Controller: var Station = '<div class="ngCellText" ng-class="col.colIndex()"><a target="_blank" href="{{row.entity.station.href}}">{{row.entity.station.text}}</a&g ...

Utilizing feature flags for Angular modules to enable lazy loading

Can we dynamically change the lazy loaded module based on a specific flag? For instance, loading module A if the flag is active and module B otherwise. The crucial aspect is that both modules should use the same path. Approach #1 - dynamic loadChildren() ...

Using Cordova to create an accordion list on an HTML webpage

I am in need of an accordion list implementation for the given HTML code. I specifically want it to expand when 'Technical' is clicked, and collapse upon clicking again. Here is the HTML code: <!-- Techincal --> <div class= ...

Updating the $location variable from the $rootScope perspective

I am facing an issue with my web app which is built using AngularJS. I have two functions in my code - one declared on the $rootScope and the other on the $scope. The code snippets are shown below: app.js app.run(function ($rootScope, $location) { $roo ...

Angular 4 fetches the number obtained from a GET request

In my spring-boot back-end app, I have defined a query as shown below: @Query("SELECT COUNT(*) " + "FROM Foo " + "WHERE name = :name and surname = :surname ") Integer countByNameAndSurname(@Param("name") String name, @Param("surnam ...

Tips for maintaining an active Angular PWA while your device is in doze mode

We are currently in the process of creating an angular progressive web application that receives updates from a LightStreamer Server and displays notifications to the user. Since PWAs serve as alternatives to native apps, we are aiming for our app to rem ...

Tips for executing a function when nearing the bottom of a scroll:

I have incorporated the angular2-infinite-scroll plugin, specifically version 0.1.4. You can view my plunker here. Currently, the function onScrollDown() only runs once at the beginning when scrolling. I attempted to adjust the values for infiniteScroll ...

Whenever I navigate to a new page in my NEXTJS project, it loads an excessive number of modules

I am currently working on a small Next.js project and facing an issue where the initial load time is excessively long. Whenever I click on a link to navigate to a page like home/product/[slug], it takes around 12 seconds to load due to compiling over 2000 ...

Stopping the parent onclick event from propagating to a child element within a bootstrap modal

I am currently working with angularjs and bootstrap, incorporating nested onclick events using Angular's ng-click in various HTML elements. One is located in a table header to display different sort icons and execute the sorting logic when the header ...

Utilizing Angular for making API requests using double quotes

I am experiencing an issue with my service where the double quotation marks in my API URL are not displayed as they should be. Instead of displaying ".." around my values, it prints out like %22%27 when the API is called. How can I ensure that my ...

What is the best way to extract URLs with varying numbers of slashes in angular.js?

My goal is to create an Angular website focused on managing files, allowing users to navigate through a file system tree similar to how it's done on Github (example: github.com/angular/angular.js/tree/master/path/to/my/file.js. I want to extract the ...

Employing the filter or find technique to extract an element contained within a JSON data structure

Is it possible to retrieve one of these items using the filter or find method to search for a match within the fiberAgrupations array? I attempted the following: const landlineRate = this.monolineJsonRates[0].cambioCaudal.getAll() .filter(landlinedRat ...

The $ionicModal fails to reflect any updates in the content when changes are made in the controller while the modal is open

My $ionicModal setup looks like this: <ion-modal-view> <ion-content> <ion-slide-box> <ion-slide ng-repeat="display in VideoCtrl.display track by $index" > <div class="card"> <div class="item item-divid ...

"Discovering the secrets of incorporating a spinner into Angular2 and mastering the art of concealing spinners in Angular

When experiencing delay in image loading time, I need to display a spinner until the image loads completely. What is the best way to achieve this on the Angular 2 platform? <div id='panId' class="container-fluid" > This section ...

I am currently working on developing an application that is designed to automatically place sequential phone calls from a predefined list of numbers

I am currently working on an application for a friend who works in sales. The goal of this app is to automatically make phone calls one after another, without any interruptions. Once a call ends, the app will immediately dial the next number on the list. T ...

How can the edit feature be implemented in AngularJS?

I am struggling with implementing an edit field in AngularJS. Can someone please help me with this? Here is the code for my CRUD operations: var app = angular.module('myApp', []) app.controller('myCtrl', ['$scope', functio ...

Error encountered in Angular after consolidating JavaScript files into a single file: [$injector:modulerr]

After developing an Angular application, everything seemed to be functioning well when I included the controllers.js, routes.js, directives.js files separately in index.html. However, upon attempting to combine these files into a single js file using gul ...

The ngIf statement in the template isn't functioning properly after a refresh; instead, it is causing a redirection to the homepage

I've been developing with Angular 7, trying to display a <div> ... </div> based on multiple values that I declared as : Boolean = false; in the .ts file. These values are updated in ngOnInit, but for some reason, the page keeps redirecting ...

How to Turn Off GridToolbarExport Menu in React Mui DataGrid

Can someone assist me in disabling the menu in GridToolbarExport? This is how my MUI Data Grid is set up: <DataGrid localeText={{ toolbarExport: "Export as CSV", }} disableColumnMenu={true} components={{ Toolbar ...

Creating a cutting-edge mobile application using Ionic for the frontend and Django for the backend development

I'm in the process of creating a mobile application that utilizes Ionic (AngularJS) for the frontend and Django for the backend. I'm curious to find out if it's feasible to leverage Django to provide data as a JSON web API that my app can ac ...