레일스와 비슷한 방식으로 경로를 구조화하려고합니다.
$routeProvider.when('/posts', {
controller: 'PostsCtrl',
templateUrl: '/views/posts.html'
});
$routeProvider.when('/posts/new', {
controller: 'PostsCtrl',
templateUrl: '/views/posts.html',
doNew: true
});
$routeProvider.when('/posts/:postID', {
controller: 'PostsCtrl',
templateUrl: '/views/posts.html'
});
$routeProvider.when('/posts/:postID/edit', {
controller: 'PostsCtrl',
templateUrl: '/views/posts.html',
doEdit: true
});
PostCtrl
가 맨 아래에 다음과 같습니다 : 경로가 /posts/new
또는 /posts/2
또는 /posts/2/edit
때
if ($routeParams.doNew) {
console.log('action: new');
} else if ($routeParams.doEdit) {
console.log('action: edit', $routeParams.postID);
} else if ($routeParams.libraryID) {
console.log('action: show', $routeParams.postID);
} else {
console.log('action: index');
}
action: show
가 인쇄 나는이와 비슷한 경로 설정이 있습니다. 컨트롤러가 적절한 조치를 취하도록 필터링하려면 무엇을 할 수 있습니까?
99 % 각 경로마다 별도의 컨트롤러를 만들어야합니다. –
그건 사실이 아닙니다. 다른 컨트롤러를 사용하는 이유는 범위에서 설정 한 데이터가 근본적으로 다른 경우입니다. 새로운 것, 편집하는 것, 사실상 동일하다는 것을 보여주기 위해 동일한 컨트롤러를 재사용하는 것이 합리적입니다. '목록'보기는 다를 수 있으며 자체 컨트롤러/템플릿임을 보증 할 수 있습니다. – dtabuenc