2016-11-18 41 views
0

我正在構建一個包含一年中每個月的內容的Ionic應用程序。我想在用戶啓動應用程序時顯示當月的內容。之後,用戶仍然可以選擇其他月份的內容(通過側面菜單)。Ionic - 動態啓動頁面沒有得到stateParams

我能夠做到這一點$ ionicPlatform.ready如下:

.run(function($ionicPlatform, $filter, $location, $rootScope, $state) { 
    $ionicPlatform.ready(function() { 
     // 
     // removed other code here for clarity 
     // 
     date = new Date(); 
     month = $filter('date')(date, 'M'); 
     newPath = '/maand/' + month + '/groenten'; 
     $location.path(newPath); 
     $rootScope.$apply(); 
    }); 
}) 

這需要我正確的觀點,但這不從就要到URL獲得一個月的參數在標題中顯示動態標題。有誰能幫我解決這個問題嗎?謝謝!

回答

0

您應該使用$ stateProvider來更改傳遞參數的狀態。 實施例:

.config(function($stateProvider, $urlRouterProvider) { 
     $stateProvider 
      .state('your-state', { 
       url: '/your-url', 
       params: {month: ""}, 
       templateUrl: 'templates/your-template.html', 
       controller: 'YourController' 
      }) 

更好地解釋here