I am encountering an issue where the value returned from a promise is coming back as undefined in my template. In the getLabel function, I am receiving a label as a promise and resolving it before returning it to the title in the getMenuItems function. However, when I check the page, the value is undefined. I would appreciate some guidance on why this is happening.
angular.module("peanutModule").service("navigationService", ["registrationLink", "auctionLink", "webLabel", function(registrationLink, auctionLink, webLabel) {
this.getMenuItems = function(menu) {
return [{
"title": "VIEW EVENT ITEMS",
"href": auctionLink
}, {
"title": "REGISTER FOR " + getLabel(webLabel),
"href": registrationLink
}];
};
function getLabel(label) {
var original = Promise.resolve(label);
var cast = Promise.resolve(original);
cast.then(function(value) {
console.log('value: ' + value);
return value;
});
console.log('original === cast ? ' + (original === cast));
}
}]).service("ticketItemsService", ["APIDataProvider", "sharedOrganization", "ItemsCountFactory", function(APIDataProvider, sharedOrganization, ItemsCountFactory) {
var dataProvider = new APIDataProvider("ItemsCount");
dataProvider.setModelFactory(ItemsCountFactory);
this.get = function() {
return sharedOrganization.get().then(function(organization) {
return dataProvider.get("organizations/" + organization.org_id + "/items");
});
};
}]).factory("registrationLink", ["slug", function(slug) {
// return "https://test.net/register.php/?id=" + slug;
return "https://test.net/thezone/" + slug + "/register";
}]).factory("auctionLink", ["slug", function(slug) {
return "https://test.net/thezone/" + slug + "/items";
}]).factory("webLabel", ["sharedOrganization", function(sharedOrganization) {
this.get = function() {
return (isValidOrganization() ? $q.resolve : stackPromise)(org_data);
};
return sharedOrganization.get().then(function(organization) {
return organization.web_label;
});
}]);