여기서 무슨 일이 일어나고 있는지 잘 모르겠습니다.
angular.module('myApp', [
'ngRoute',
'myApp.controllers',
'myApp.filters',
'myApp.services',
'myApp.directives'
]).
config(function ($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: '/partials/homepage',
controller: 'MyCtrl1'
}).
when('/about/:id', {
templateUrl: '/partials/'+$routeParams.id,
controller: 'MyCtrl1'
}).
when('/funnel', {
templateUrl: '/partials/funnel',
controller: 'MyCtrl2'
}).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
});
/ 또는 / about / : id를 찾아도 $ routeParams가 정의되지 않습니다.
$routeParams
사용하려면 서비스 를 주입해야 합니다. 그러나 귀하의 경우에는 routeparam을 기반으로 템플릿을 동적으로 결정하려는 것처럼 보입니다. 앱 초기화 단계의 일부로 한 번만 실행되는 앱의 구성 단계에서 직접 수행 할 수 없습니다 (또한 $routeParams
그러한 공급자가 없기 때문에 앱의 구성 단계에서 삽입 할 수도 있음). 동적 템플릿을 검색하는 방법을 찾고 싶을 templateUrl
수 있으며이 앵귤러를 지원하기 위해이 기능을 사용 하여 모든 경로 매개 변수 (함수에서 인수가 될)를 기반으로 템플릿 URL을 동적으로 결정할 수있는 기능을 제공합니다.
다음과 같이 할 수 있습니다.
when('/about/:id', {
templateUrl: function(routeParam){ //register it as function
return '/partials/' + routeParam.id; //Get the id from the argument
},
controller: 'MyCtrl1'
}).
문서 에서 바로 .
templateUrl – {string = | function () =} – ngView에서 사용해야하는 html 템플릿의 경로를 반환하는 경로 또는 함수입니다. templateUrl이 함수이면 다음 매개 변수와 함께 호출됩니다
{Array.<Object>}
.-현재 경로를 적용하여 현재 $ location.path ()에서 추출 된 경로 매개 변수
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다