2016-09-08 3 views
1

코드입니다 :

$routeProvider.when('/devices-list', { 
     templateUrl: 'Views/Layouts/devices-list.html', 
     controller: 'deviceLibraryController' 
    }); 

그러나 나는 그렇게 바로 가기를 갖고 싶어.

$routeProvider.when('/devices-list', { 
      templateUrl: 'Views/Layouts' + this.path +'.html', // where this.path would be '/device-list' 
      controller: 'deviceLibraryController' 
    }); 

이렇게 비슷한 단계가 있습니까?

업데이트 : 내가 거기 $routeProvider.when('/:name', {...})와 비슷한 상황을하는 한 가지 방법이지만 변수 방법으로 모든 :name을 구문 분석 발견

. 필요한 것은 경로가 이미 지정되어 있으며 $ routeProvider에서 경로를 검색하여 templateURL을 반환합니다.

the reference에 명시된 바와 같이

답변

0

,

templateUrl - {(문자열 | 기능) =} - 경로 또는 ngView 사용해야하는 HTML 템플릿에 경로를 반환 기능. templateUrl 함수이면

, 그것은 다음 파라미터를 호출한다 :

{Array.<Object>} - (+) 전류 경로

을 적용하여 현재 $의 location.path로부터 추출 된 경로 파라미터

오타가있는 것으로 나타 났지만 route parameters param is an object은 개체 배열이 아닙니다.

그래서 할 수

$routeProvider.when('/devices-list/:phrase', { 
    templateUrl: (params) => 'Views/Layouts' + params.phrase +'.html', 
    ... 
}); 
관련 문제