Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I followed a tutorial that showed how to use angularjs and load json data based on menu slug and show it in the page. The demo is here: https://dl.dropboxusercontent.com/u/28763/angular-tutorial/index.html#/page/home

When I refresh the homepage (https://dl.dropboxusercontent.com/u/28763/angular-tutorial/index.html#/page/home), I get a js error in firebug that notes:

$digest already in progress

or

$rootScope.pages is undefined

This usually happens the time after the initial pages.json load. So if I update the pages.json file, I can hit refresh and see the new data, but if I refresh again I get the error. If you click a menu item, About for example, you will see the About page. Click home and it is there. Refresh the browser and get an error.

Also the page shows where the content should render:

{{page.title}}
{{page.content}}

...rather than the title and content. I am super new to AngularJS and am not finding a reason why this isn't working here consistently.

I have the .otherwise({redirectTo: '/home'}); in there, and it does redirect there, however, the data doesn't always do the same...

If this is due to the pages.json file loading quick enough, how do I go about making sure the file is completely loaded before moving on? Or might there be another reason someone sees?

EDIT: Here is a Plunker of my setup: http://plnkr.co/edit/8QpsLHhPA58uZnbAHgck?p=preview

share|improve this question
    
Make sure to set the data using .then()/.success() on your $http call. Also make sure you're not using $scope.$apply() while angular is doing it's own digest calls. –  Christopher Marshall Jul 1 at 20:52
1  
Not sure I follow the .then()... like so: $http.get('/pages.json').then(function (data){ $rootScope.pages = data; }); ? –  jasonflaherty Jul 1 at 21:17
    
Maybe its better to resolve the process of getting data from your json file this way you can be sure that data is avalabe befor anything loads –  xe4me Jul 1 at 21:27
    
Exactly like that @jasonflaherty –  Christopher Marshall Jul 1 at 21:41
    
$http.get('pages.json').then(function (data){ console.log(data); $rootScope.pages = data; }); does return data in console... why isn't it passing it to $rootScope.pages? –  jasonflaherty Jul 1 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.