반응형
angularjs 루트에 옵션 파라미터 값을 설정할 수 있습니까?
옵션 파라미터(템플릿과 컨트롤러는 동일하지만 존재하지 않는 파라미터는 무시해야 합니다)를 사용하여 루트를 설정할 수 있습니까?
그래서 다음 두 가지 규칙을 쓰는 대신, 하나만 있는 건가요?
module.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/users/', {templateUrl: 'template.tpl.html', controller: myCtrl}).
when('/users/:userId', {templateUrl: 'template.tpl.html', controller: myCtrl})
}]);
이와 같은 것([이 파라미터는 옵션])
when('/users[/:userId]', {templateUrl: 'template.tpl.html', controller: myCtrl})
//note: this previous doesn't work
나는 그들의 서류에서 아무것도 찾을 수 없었다.
Angular가 지금 이 일을 지지하고 있는 것 같아요.
의 최신 (v1.2.0) 문서:
path에는 물음표가 붙은 임의의 이름 있는 그룹을 포함할 수 있습니다( ).:name?)
@g-eorge 언급처럼 다음과 같이 만들 수 있습니다.
module.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/users/:userId?', {templateUrl: 'template.tpl.html', controller: myCtrl})
}]);
옵션 파라미터가 필요한 만큼 만들 수도 있습니다.
@jlareau의 답변은 https://stackoverflow.com/questions/11534710/angularjs-how-to-use-routeparams-in-generating-the-templateurl를 참조하십시오.
함수를 사용하여 템플릿 문자열을 생성할 수 있습니다.
var app = angular.module('app',[]);
app.config(
function($routeProvider) {
$routeProvider.
when('/', {templateUrl:'/home'}).
when('/users/:user_id',
{
controller:UserView,
templateUrl: function(params){ return '/users/view/' + params.user_id; }
}
).
otherwise({redirectTo:'/'});
}
);
사실 저는 OZ_가 맞을 수도 있다고 생각합니다.
루트가 있으면'/users/:userId'으로 이동합니다.'/users/'(후행/에 주의해 주세요),$routeParams컨트롤러에 있는 오브젝트는userId: ""1.1.5로 설정합니다.매개 변수는 없습니다.userId완전히 무시당하진 않지만 그게 최선인 것 같아요.
언급URL : https://stackoverflow.com/questions/17510962/can-angularjs-routes-have-optional-parameter-values
반응형
'programing' 카테고리의 다른 글
| mongodb에서 .bson 파일 형식을 Import하는 방법 (0) | 2023.03.22 |
|---|---|
| 워드프레스 add_rewrite_tag(), add_rewrite_rule() 및 post_link() (0) | 2023.03.22 |
| Angular에서 쿼리 파라미터를 설정하려면 어떻게 해야 합니까?루트를 안 하고 JS? (0) | 2023.03.22 |
| Oracle 테이블에서 중복 행 제거 (0) | 2023.03.22 |
| Jackson의 readValue 및 readTree: 어떤 경우에 사용할 것인가? (0) | 2023.03.17 |