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

  • Home
  • SEARCH
  • 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 8467415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:38:17+00:00 2026-06-10T15:38:17+00:00

When my angular app first loads, I need to make a couple requests for

  • 0

When my angular app first loads, I need to make a couple requests for some fairly large data. This data is then used in controllers and services to determine how to display the page. I’m getting all sorts of JavaScript errors because the controllers and services are trying to access this data before the request has returned.

I know in the HTML pages, you can bind to this asynchronous data, and angular will populate it for you when the request returns. However, I have some pretty complex logic happening in my controllers and services based on this data. So, I guess I have 2 questions.

  1. Is there anyway to somehow work with asynchronous data in the controllers and services?
  2. Is there a way to prevent angular from trying to render the page until after the data has returned? This basically makes the data requests synchronous, and I am ok with that. This would only be on the initial full HTML page load.

My attempt at a jsFiddle showing this can be found here: http://jsfiddle.net/sES9T/

  • 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-10T15:38:19+00:00Added an answer on June 10, 2026 at 3:38 pm

    The basic flow should be like this: Inside your controller function, make the $http request, and in the success() callback, set your $scope variables as needed. Is your flow different from that?

    Also, use the ng-show directive to hide your DOM elements until the scope has the data you need.

    Your controller will look something like this:

    MyCtrl = ( $scope, $http ) ->
      promise = $http.get "/url"
      promise.success ( data ) ->
        $scope.foo = data
    

    And your view will look like this:

    div(ng-show="foo")
      p Here is my data, and some other stuff
      p {{ foo }}
    

    EDIT

    I’ve modified your jsfiddle here:

    http://jsfiddle.net/sES9T/4/

    It works as expected, the problem was that you were trying to access properties on undefined variables, which was throwing an error. Also, on the third test, the variable was named wrong, but still needs to be checked when named right.

    I’d recommend coffeescript, since those if statements can be made a lot more terse with the existential (?) operator, like so:

    myLargeData?.data
    

    That code will check if myLargeData is defined and non-null before trying to access it’s properties, like I had done manually above. If it IS undefined or null, it will return undefined, instead of causing an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I access hidden fields in angular? I have an app, where I
Instead of posting in Angular mailing list, I think this may be more of
I need to make a conversion from a general angular_velocity to degrees/second. To illustrate
I am trying to match patterns in perl and need some help. I need
Okay, first off, I am build a web app using AngularJS and node.js. I
I have a working Angular.js app with HTML5 mode enabled. $location.Html5mode(true).hashbang(!); What I want
I trying to get on my feet with angular.js using the seed app. When
In my AngularJS node.js app based on angular-express-blog and express-coffee I have an issue
I am new to angular.js and currently writing my first project. Currently my controllers
In my app I need to use body parser to request params (Node.js AngularJS

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.