Is there a specific approach for linking together two AngularJs service calls and executing a function with the obtained data?

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!

Answer №1

When looking at the

SocialMediaUserService.channelProfiles
function, it seems to be structured in this manner:

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

};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using VueJs's createElement() to dynamically insert HTML content

I am currently working on a component that converts all icons to SVG format. By the end of my code, I have included the following: return createElement('i', '<SVG>CODE</SVG>' ) In the spot where the SPA ...

Angular offers the ability to implement various filter options such as selecting, using checkboxes, and displaying results

I recently came across some code that I need help with. The code snippet can be found here: https://jsfiddle.net/Dimetrius/58917Ldt/ I am looking to implement filtering by select and checkbox options, followed by displaying the result upon clicking a butt ...

A more efficient method for refreshing Discord Message Embeds using a MessageComponentInteraction collector to streamline updates

Currently, I am working on developing a horse race command for my discord bot using TypeScript. The code is functioning properly; however, there is an issue with updating an embed that displays the race and the participants. To ensure the update works co ...

Choose Selectize.js to auto-populate inputs

I am currently using selectize.js for my project: $("#abc").selectize({ valueField: 'name', labelField: 'name', searchField: ['name'], plugins: ['remove_button'], createOnBlur: true, ...

The issue with hiding and showing elements using JavaScript during drag and drop functionality

In my code, I have two boxes with IDs box1 and box2, These boxes can be dragged and dropped into the boxleft element, Upon dropping them, the background image is removed and only the name appears in the box, My issue is that when loading values into box ...

Experiencing issues with the URL after installing Grunt?

click here to see the image descriptionI have successfully installed AngularJS Development with Yeoman, Grunt, and Bower. When I run the server using grunt server, it starts running without any issues. However, the URL that is being passed looks like this: ...

Is it possible in Typescript to assign a type to a variable using a constant declaration?

My desired outcome (This does not conform to TS rules) : const type1 = "number"; let myVariable1 : typeof<type1> = 12; let type2 = "string" as const; let myVariable2 : typeof<type2> = "foo"; Is it possible to impl ...

Error: Node-Sass - Unable to download win32-x64-57_binding.node

Currently in the process of getting a retired colleague's program up and running, but when attempting to execute meteor run I encounter this error. While loading package materialize:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" dat ...

Exploring nested selection with css and utilizing the ::focus pseudo class

Is it possible, using CSS, to target the helpTextInvalid class when the div element with the selectize-input class is in focus? <html> <head> <body> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/lib ...

Retrieve information from a JSON document

My project involves a bookStore with a list of books that I am working on. I am trying to extract all the book data from a JSON file and display them in a card view on a webpage. Although my code is error-free and seems to be functioning properly, the da ...

Send user a notification upon detecting changes in the database - using JavaScript and AJAX!

Hey there! I'm diving into the world of JavaScript and AJAX for the first time, and I could really use some guidance on a particular issue. I'm looking to implement a feature where the user is notified whenever there is a change in a value of a ...

Discovering which chip has wrapped to the next line in Material UI Autocomplete can be found by closely inspect

Currently, I am working with a Material UI autocomplete feature that functions as follows: https://i.sstatic.net/4LrwI.png My goal is to determine when the fourth chip wraps to the next line within the autocomplete so that I can proceed with additional c ...

Launching Angular 2 application on Heroku

Previously, I would combine my Angular 1 and Rails applications and deploy them on Heroku, which always went smoothly. However, now that I've transitioned to Angular 2, I'm looking to segregate my Angular and Rails code. I've successfully cr ...

Gain access to PowerBI reports effortlessly without the need to input any credentials

Seeking guidance on calling Power BI reports from an ASP.NET C# web application while passing credentials, specifically without utilizing Azure AD. Access has been granted to certain users in the Power BI Service workspace with view permissions. We aim t ...

I'm having trouble grasping the concept of serving gzip-compressed JavaScript and CSS files

Why is it important to serve compressed JavaScript and CSS files? I understand that it reduces file size, but does the browser/webserver have to decompress them to read them? It's been mentioned that the webserver handles the compression. Does this me ...

Include the selected class in the relative URL

I am attempting to apply a highlight class to my selected category: My code looks like this : <div id="category"> <ul> <a href="category.php?c=electronic"> <li>Electronic</li> </a> ...

What is the best way to set the v-model property to an object that is constantly changing

I'm in the process of creating a dynamic form that allows users to add additional fields by simply clicking on a button labeled "adicionar condição." The concept is similar to what can be seen in the screenshot below: https://i.stack.imgur.com/Mpmr6 ...

What is causing the Angular-UI TypeAhead code to display all items instead of filtered items?

I have been experimenting with the angular-ui typeahead directive to create a filtered input box that only shows items based on what has been typed. However, my current code is displaying all the items instead of just the filtered ones. If you'd like ...

JavaScript is having trouble locating the HTML select element

Having trouble selecting the HTML select element with JavaScript? You're not alone. Despite trying different solutions found online, like waiting for the window to fully load: window.onload = function(){ var opt = document.getElementsByName("prod ...

Tips for sharing data between two components

In my project, I have a customized Shared Component which consists of an input search bar with a "continue" button. This Shared Component is being utilized within two other components - the buy component and sell component. The challenge I am encountering ...