javascript - How to stall angular execution until JSON has been loaded? -


I have an angular application that needs to load app config data from some JSON, it is wrapped in a service, The problem that gets injected into the controllers is that I should wait until the controllers have successfully loaded json. In other words, load it synchronously. I want to request this json file and the app is not nothing until we get it back. I do not know what is the "proper angular" way to do this, suggestion?

use angular Bootstrap () .

  var myApp = angular.module ('myApp', []); // Announce your remaining app, e.g. MyApp.controller (... angular.element (.document) .ready (function () {jQuery.getJSON ('/ api / my-app / config', function (data) {// what you want with `data` Angular.bootstrap (document.getElementById ('my-app'), ['myApp']);});})   

Note ::

    < Li> Feel free to use any other method to get your config JSON, jQuery.getJSON ()
  • (document) .ready ( ) and AJAX calls, consider using the promises, so that they can be together
  • This code is not spam, you may want to make a small change Interpretation will

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -