$routeParams is empty in main controller

后端 未结 6 889
北海茫月
北海茫月 2020-12-15 04:41

I have this piece of layout html:


  
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 05:09

    had the same problem, and building off what Andre mentioned in his answer about $routeParams taking a moment to load in the main controller, I just put it in a timeout inside my MainCtrl.

    angular.module('MyModule')
      .controller('MainCtrl', function ($scope, $routeParams, $timeout) {
    
        $timeout(function(){
          // do stuff with $routeParams
          console.log('routeParams:'+JSON.stringify($routeParams));
        }, 20);
    
      });
    

    20ms delay to use $routeParams is not even noticeable, and less than that seems to have inconsistent results.

    More specifically about my problem, I was confused because I had the exact same setup working with a different project structure (yo cg-angular) and when I rebuilt my project (yo angular-fullstack) I started experiencing the problem.

提交回复
热议问题