Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way you do it is perfectly fine (I prefer using state='loading' and keep things a little bit more flexible.)</p> <p>Another way of approaching this problem are promises and <code>$routeProvider resolve</code> property. Using it delays controller execution until a set of specified promises is resolved, eg. data loaded via resource services is ready and correct. Tabs in Gmail work in a similar way, ie. you're not redirected to a new view unless data has been fetched from the server successfully. In case of errors, you stay in the same view or are redirected to an error page, <strong>not</strong> the view, you were trying to load and failed.</p> <h3>You could configure routes like this:</h3> <pre><code>angular.module('app', []) .config([ '$routeProvider', function($routeProvider){ $routeProvider.when('/test',{ templateUrl: 'partials/test.html' controller: TestCtrl, resolve: TestCtrl.resolve }) } ]) </code></pre> <h3>And your controller like this:</h3> <pre><code>TestCtrl = function ($scope, data) { $scope.data = data; // returned from resolve } TestCtrl.resolve = { data: function ($q, DataService){ var d = $q.defer(); var onOK = function(res){ d.resolve(res); }; var onError = function(res){ d.reject() }; DataService.query(onOK, onError); return d.promise; } } </code></pre> <h3>Links:</h3> <ul> <li><a href="http://egghead.io/lessons/angularjs-resolve" rel="nofollow noreferrer">Resolve</a></li> <li>Aaa! Just found an excellent (yet surprisingly similar) explanation of the problem on SO <a href="https://stackoverflow.com/questions/11972026/delaying-angularjs-route-change-until-model-loaded-to-prevent-flicker">HERE</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload