2017-05-10 15 views
0

所以我知道如何與路由系統在angularjs工作,檢查:反正是有自動像.NET數據註解angularjs路由

 .when('/96', { 
      templateUrl: "96.html", 
      animation: 'present' 
     }) 
     .when('/96/moharram', { 
      templateUrl: "96_moharram.html", 
      animation: 'present' 
     }) 
     .when('/96/safar', { 
      templateUrl: "96_safar.html", 
      animation: 'present' 
     }) 
     .when('/96/shaban', { 
      templateUrl: "96_shaban.html", 
      animation: 'present' 
     }) 
     .when('/96/shaban/01', { 
      templateUrl: "96_shaban_01.html", 
      animation: 'present' 
     }) 
     .when('/96/shaban/02', { 
      templateUrl: "96_shaban_02.html", 
      animation: 'present' 
     }) 
     .when('/95', { 
      templateUrl: "95.html", 
      animation: 'past' 
     }) 

到目前爲止,沒有任何問題。但是這個概念是每年創造12個月,接近30天。所以,無論如何,我可以說,例如當頁面在「/ 96」(和隔年),當用戶點擊moharram(月份)頁面應該去/96_mohrram.html或/ 96/moharram。 HTML。

回答

1

templateUrl可能是一個函數,它的參數爲$routeParams。鑑於和路徑參數,這裏就是你可能會尋找一個例子:

.when('/:year/:month', { 
    templateUrl: function($routeParams) { 
     return $routeParams['year'] + "/" $routeParams['month'] + ".html" 
    }, 
    animation: 'past' 
}) 

瞭解更多關於$routeProvider

+0

每次我嘗試你的代碼是給了我一個奇怪的404錯誤:63342/beiraq.com /beiraq.com/index.html.html。和整個應用程序崩潰。 –

+0

得到了圖片。謝謝 –