I am trying to chain two service calls together and then filter the data using a forEach loop
. However, I am encountering a TypeError: "SocialMediaUserService.channelProfiles is not a function" error in Chrome.
Interestingly, this code works perfectly fine in IE without any warnings or errors. :)
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 how my
SocialMediaUserService.channelProfiles
service call is structured:
this.channelProfiles = function () {
var channelProfiles = pullSocialMediaData('list_channel_profiles.json');
console.log("Channel Profiles Logged: " + channelProfiles);
return channelProfiles;
}
This is how my
SocialMediaUserService.returnBrandProfileID
service call is structured:
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: Here is the pullSocialMediaData function being used:
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!