Could I achieve this by making toys
a deferred API request, so that when executed the value of res
is returned and becomes the final result when toysData
is logged?
The Promise
const toys = (url) => {
const deferred = $q.defer();
const params = {
id: url,
};
ToysModel.get(params, (data) => {
deferred.resolve(data);
}, (error) => {
deferred.reject(error);
});
return deferred.promise;
};
The Request
let toysData = toys(uuid)
.then(res => res);
console.log(toysData);
API Call
export default class ToysModel {
constructor($resource, ENV) {
const url = `${ENV.apiEndpoint}/`;
const actions = {
oembed: {
url: `${ENV.apiEndpoint}/toy/:id`,
method: 'get',
params: {
id: '@id',
},
crossDomain: true,
},
};
return $resource(url, {}, actions);
}
}