Reputation: 1515
I would like to chain these two service calls, and with the results perform a forEach loop
to filter my data, but get a TypeError: "SocialMediaUserService.channelProfiles is not a function" message in Chrome.
However, this works in IE, and no warning or message. :)
function getChannelProfiles() {
GetUserAccessService.returnBrandProfileID().then(function (brandProfileID) {
SocialMediaUserService.channelProfiles().then(function (channelProfiles) {
channelProfiles.forEach(function (channel) {
if (channel.brand_profile_id === brandProfileID && channel.channel_type === 'facebook') {
$scope.facebookChannels.push(channel.channel_url);
console.log($scope.facebookChannels);
}
});
});
});
}
EDIT: This is my SocialMediaUserService.channelProfiles
service call:
this.channelProfiles = function () {
var channelProfiles = pullSocialMediaData('list_channel_profiles.json');
console.log("Channel Profiles Logged: " + channelProfiles);
return channelProfiles;
}
This is my SocialMediaUserService.returnBrandProfileID
service call:
this.returnBrandProfileID = function () {
var brandProfileID = $q.defer();
if (angular.isUndefined($sessionStorage.brandProfileID)) {
GetDataService.getItems('GetUserAccess/' + $cookies.get('authenticationID'))
.success(function (accessObject) {
brandProfileID.resolve(accessObject.FusewareID);
})
.error(function (error, status) {
console.error('Fuseware API error: ' + error + ' Status message: ' + status);
});
}
else {
brandProfileID.resolve($sessionStorage.brandProfileID);
}
return brandProfileID.promise;
};
Edit 2: This is the pullSocialMediaData function:
function pullSocialMediaData(url) {
var userData = $q.defer();
GetFusionDataService.getItems(url)
.success(function (data) {
userData.resolve(data);
})
.error(function (error, status) {
});
return userData.promise;
}
Thank you!
Upvotes: 0
Views: 185
Reputation: 320
The SocialMediaUserService.channelProfiles
might be designed like this :
this.channelProfiles = function () {
var channelProfilesPromise = new Promise(function (resolve, reject){
pullSocialMediaData('list_channel_profiles.json').then(function(result){
console.log("Channel Profiles Logged: " + result);
resolve(result);
});
});
return channelProfilesPromise
};
Upvotes: 2