[英]What is the correct way/can you chain two AngularJs service calls and then perform a function with the returned data?
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. 我想链接这两个服务调用,并在结果中执行forEach loop
以过滤我的数据,但在Chrome中收到TypeError:“ SocialMediaUserService.channelProfiles不是函数”消息。
However, this works in IE, and no warning or message. 但是,这在IE中有效,并且没有警告或消息。 :) :)
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: 编辑:这是我的SocialMediaUserService.channelProfiles
服务调用:
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: 这是我的SocialMediaUserService.returnBrandProfileID
服务调用:
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: 编辑2:这是pullSocialMediaData函数:
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! 谢谢!
The SocialMediaUserService.channelProfiles
might be designed like this : SocialMediaUserService.channelProfiles
可能设计如下:
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
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.