2015-02-03 1 views
1

저는 ionic framework과 angularjs에 익숙하지 않습니다. 목록 항목이 app.single에 매핑되는 방식을 이해하려고합니다. 다른 예제에서는 부모 "목록"상태에 대해 "list.item"의 사용이 발견되었지만 저에게는 그다지 효과가 없었습니다 (egghead.io tutorial).
나는 사이드 메뉴와 함께 기본 이온 응용 프로그램을 사용하고 있습니다.
누군가가 app.single이 재생 목록 항목에 어떻게 매핑되는지 설명해주세요.어떻게 ion framework에서 app.single 작동합니까?

playlists.html :

<ion-view view-title="Playlists"> 
    <ion-content> 
    <ion-list> 
     <ion-item ng-repeat="playlist in playlists" href="#/app/playlists/{{playlist.id}}"> 
    {{playlist.title}} 
     </ion-item> 
    </ion-list> 
    </ion-content> 
</ion-view> 

playlist.html

<ion-view view-title="Playlist"> 
    <ion-content> 
    <h1>Playlist</h1> 
    </ion-content> 
</ion-view> 

controller.js

.controller('PlaylistsCtrl', function($scope) { 
$scope.playlists = [ 
{ title: 'Reggae', id: 1 }, 
{ title: 'Chill', id: 2 }, 
{ title: 'Dubstep', id: 3 }, 
{ title: 'Indie', id: 4 }, 
{ title: 'Rap', id: 5 }, 
{ title: 'Cowbell', id: 6 } 
]; 
}) 

.controller('PlaylistCtrl', function($scope, $stateParams) { 
}); 

이 playlists.html에서

.state('app.playlists', { 
    url: "/playlists", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/playlists.html", 
     controller: 'PlaylistsCtrl' 
    } 
    } 
}) 

.state('app.single', { 
    url: "/playlists/:playlistId", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/playlist.html", 
     controller: 'PlaylistCtrl' 
    } 
    } 
}); 
+0

내 답변에 대한 귀하의 생각은 무엇입니까, @ vikramaditya234? – filipvkovic

+0

'sidemenu' 청사진과 함께 제공되는 상용구 이온 코드에는 "_Playlist ** s ** Ctrl_"과 "_PlaylistCtrl_"이라는 거의 동일한 변수 이름을 가진 두 개의 컨트롤러가 있습니다. 이것은 첫눈에 꽤 혼란 스러울 수 있습니다. ** PlaylistController **와 ** PlaylistItemController **가있는 것이 훨씬 더 명확했을 것입니다. 사실, 이것은 더 좋을 것입니다 : ** ItemListController **와 ** ItemDetailController **. 나쁜 명명은 정말로 당신을 죽일 수 있습니다 .. – ccpizza

답변

2

을 app.js, 각 재생 목록 항목에 대한 템플릿을 대상 URL을 제공하는 HTML 태그가 있습니다.

href="#/app/playlists/{{playlist.id}}" 

그래서, 일단 현재 목록의 항목에서 사용자 탭, 그는 "/app/playlists/{{playlist.id}}"페이지로 리디렉션됩니다.

그런 다음 각 컨트롤러를 원하는 URL에 연결하는 app.js에 집중하십시오.

url: "/playlists/:playlistId", 

'app.single'상태가 각 재생 목록 항목에 연결되는 부분입니다. 이 경우 '/ app'는 'app'상태 정의의 추상 매개 변수에 의해 생략됩니다.

+0

답장을 보내 주셔서 감사합니다, 나는 개념을 이해합니다. 나는 주 이름과 URL을 혼동했다. – vikramaditya234

관련 문제