2013-09-01 103 views
5

是否可以在不寫routeProvider的情況下使用ng-view,即通過在標記部分包含路由(我認識到混合邏輯和視圖並不是最好的設計,但在這種情況下可能可以接受,因爲它實際上是條件模板)。我的路線提供商硬編碼模板角指令:沒有routeProvider的ngView?

spaceJam.config(function($routeProvider, $locationProvider) { 
    $routeProvider. 
     when('/images', { 
      template: '<ng-my-image-editor></ng-my-image-editor>' 
      }). 
     when('/videos', { 
      template: '<ng-my-video-editor></ng-my-video-editor>' 
      }). 
     when('/calendar', { 
      template: '<ng-my-calendar-editor></ng-my-calendar-editor>' 
      }). 
     otherwise({redirectTo: '/images'}) ; 

    $locationProvider.html5Mode(false); 

}); 

,而不是有這樣的事情:

<ng-view> 
    <ng-view-selection when="/images" default><ng-my-image-editor></ng-my-image-editor></ng-view-selection> 
    <ng-view-selection when="/videos"><ng-my-video-editor></ng-my-video-editor></ng-view-selection> 
    <ng-view-selection when="/calendar"><ng-my-calendar-editor></ng-my-calendar-editor></ng-view-selection> 
<ng-view> 

有另一種方法來此?

+7

也許'NG-include'將是對您有用:http://docs.angularjs.org/api/ng.directive:ngInclude – karaxuna

回答