Angular return value from one ts to another -
in angular project, have 2 ts files below:
data.ts
import { injectable } '@angular/core'; import { mystorage } '../storage'; @injectable() export class itemfromstorage { constructor(public storage: storage) { } getitemdatafromstorage(current){ this.storage.get(current).then((val) => { return val; //???? }); }; }
main.ts
import { itemfromstorage } '../data' export class item_thumb { constructor(public itemstorage: itemfromstorage) { }; fetchthumbdata(){ var data = this.itemstorage.getitemdatafromstorage(this.datanumber); console.log(data);//???? } }
from data.ts
, how return data value main.ts
?
your data.ts method should return request itself, without subscribing it:
getitemdatafromstorage(current){ return this.storage.get(current); };
and in main.ts method subscribe , receive data:
fetchthumbdata(){ var data = this.itemstorage.getitemdatafromstorage(this.datanumber).then((data) => { console.log(data);//???? }); }
Comments
Post a Comment