最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - IonicAngular - Transform Promise in callback - Storage don't get a value to use in next functions - Stack O

programmeradmin1浏览0评论

I have a token in storage memory, but on load with "get" method:

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-angular';

@Injectable({
  providedIn: 'root'
})
export class StorageService {

  constructor(private storage: Storage) {
    this.initStorage();
   }

  async initStorage() {
    await this.storage.create();
  }

  async get(key) {
    const value = await this.storage.get(key); 
    //console.log(value);
    return value;
  }

I have a "promise", and my call to API don't fill the correct value:

public getCategories () {
let wsfunction = "core_course_get_categories";
this.url = this.variaveis.URL_REST + "wsfunction=" + wsfunction + "&wstoken=" + this.storage.get('token');
console.log(this.url);
return this.http.get(this.url);
}

The final URL: https://../webservice/rest/server.php?moodlewsrestformat=json&wsfunction=core_course_get_categories&wstoken=[object Promise]

My next function use the HTTP return from API do load data:

...
this.courses.getCategories().subscribe({
next: (data) => {
console.log(data);
...

But fail because don't get values but a "object promise".

How to convert the result of "get" Storage in values, and don't in 'Promise Object'??

Any function to transform the values in promise to values in Callback format? to use in next functions in my code? because I don't want to rewrite the final functions because there is a lot of code depending on them, I wanted to solve it at the beginning of "get" storage...

I don't have problem with performance, my app don't have many interactions and don't load many amount of data.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论