$routeParams is empty in main controller

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

I have this piece of layout html:


  
6条回答
  •  感情败类
    2020-12-15 05:23

    You can simply pass values of $routeParams defined into your controller into the $rootScope

    .controller('MainCtrl', function ($scope, $routeParams, MainFactory, $rootScope) {
        $scope.contents = MainFactory.getThing($routeParams.id);
        $rootScope.total = MainFactory.getMax(); // Send total to the rootScope
    }
    

    and inject $rootScope in your IndexCtrl (related to the index.html)

    .controller('IndexCtrl', function($scope, $rootScope){
        // Some code
    });
    

提交回复
热议问题