Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:19:12+00:00 2026-06-14T19:19:12+00:00

I have a very strange problem with an angular app we are building. Whenever

  • 0

I have a very strange problem with an angular app we are building. Whenever i load some data from a resource defined like below (simplest example I could build) I get some data back wich I can use for databinding (eg. ng-repeat=’message in messages’ or as {{message.id}}) however I can never read it from javascript by accessing it as an array or object (depending on wether i used get({id:myId}) or query()).

Iterating over it only gives me keys like $get, $query, $save, etc… but no actual data.

app.factory('Message', ['$resource', function($resource) {
    return $resource('MY_URL/messages/:id', {id: '@id'});
}]);

app.service('messageService', ['$rootScope', 'Message', function($rootScope, Message) {
    var messages = Message.query();
    var selectedMessage = null;

    var service = {};

    service.get = function(id) {
                    // Problem A (see below for details)
        if (arguments.length === 1) return Message.get({id: id});
        else return messages;
    };

var MenuCtrl = function($scope, Project, messageService, otherService) {
    $scope.projects = Project.query();
    $scope.messages = messageService.get();

    // Problem B (details below)
};

At Problem A i want to be able to return a single element form a collection that has already been fetched, however i need some way to handle calls that happen before the data is ready.

At problem B i would like to process some of the fetched data and pass the result to “otherService” however i need a way to delay this until the data is ready.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:19:14+00:00Added an answer on June 14, 2026 at 7:19 pm

    I have only seen this issue come up in unit testing, and the way to get around it is by “flushing” the mock $httpBackend.

    According to the API docs:

    The $httpBackend used in production, always responds to requests with responses asynchronously. If we preserved this behavior in unit testing, we’d have to create async unit tests, which are hard to write, follow and maintain. At the same time the testing mock, can’t respond synchronously because that would change the execution of the code under test. For this reason the mock $httpBackend has a flush() method, which allows the test to explicitly flush pending requests and thus preserving the async api of the backend, while allowing the test to execute synchronously.

    Here’s an example with some context:

    // define a resource within a service
    angular.module('app.services', ['ngResource'])
      .factory('Message', function ($resource) {
        var url = ...
          , params = ...
          , actions = ...;
    
        return $resource(url, params, actions);
      }
    
    // Query the resource in a controller
    function MessagesCtrl ($scope, $routeParams, Message) {
      $scope.messages = Message.query();
    }
    
    // unit test with a mocked backend
    describe('MessagesCtrl', function() {
      var scope, ctrl, $httpBackend, messages;
    
      beforeEach(inject(function (_$httpBackend_, $rootScope, $controller) {
        $httpBackend = _$httpBackend_;
        scope = $rootScope.$new();
    
        messages = [
          {
            id: '1',
            text: 'foo',
          }, {
            id: '2',
            text: 'foo',
          }
        ]
    
        $httpBackend.expectGET('/api/messages').respond(messages);
        ctrl = $controller('MessagesCtrl', {$scope: scope});
      }));
    
      it('should get a list of messages', function () {
    
        // THE NEXT LINE WILL SOLVE THE PROBLEM
        $httpBackend.flush();
    
        expect(scope.message).toEqualData(message);
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have encountered a very strange class not found problem in our web app
Hello I have very strange problem and maybe some of you could help my.
I have encountered a very strange problem in using jQuery load() . I used
I have a very strange problem, in my terminal, if I load my binary
I have very strange problem with Doxygen: I used it to create documentation from
I have very strange problem with IsNumeric function in classic asp fail. Something like
Very strange problem with my iPhone App. We have an App that has been
I have a very strange problem. Under some elusive circumstances I fail to apply
I have this very strange problem on a big flex app where it would
I have a very strange problem in my app which only happen on Retina

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.