Created
October 21, 2015 19:33
-
-
Save paynoattn/aa6acd47a4e1e213882f to your computer and use it in GitHub Desktop.
Simple AngularJS UI-Router List/Detail View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('routerApp', ['ui.router']); | |
.config(function($stateProvider, $urlRouterProvider){ | |
$stateProvider | |
.state('beatles', { | |
abstract: true, | |
url: '/beatles', | |
templateUrl: 'beattles.html' | |
}) | |
.state('beatles.list', { | |
url: '/list', | |
// loaded into ui-view of parent's template | |
templateUrl: 'list.html', | |
controller: 'listController' | |
}) | |
.state('beatles.detail', { | |
url: '/:id', | |
// loaded into ui-view of parent's template | |
templateUrl: 'detail.html', | |
controller: 'listController' | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('routerApp', ['ui.router']);.controller('listController', ['$scope', '$http', '$state', '$location', function($scope, $http, $state, $location) { | |
$http.get('data.json').success(function(data){ | |
$scope.thisAlbum = $state.params.id; | |
$scope.albums = data; | |
}); | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="nav"> | |
<a href="#/">Back to Full Album List</a> | |
</div> | |
<div class="albumDetail" ng-repeat="album in albums | filter: {id: thisAlbum}"> | |
<h2>{{album.album}}</h2> | |
<span>{{album.date}}</span> | |
<p>{{album.desc}}</p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="col-sm-4 album" ng-repeat="album in albums"> | |
<div> | |
<a href="#/beatles/{{album.id}}"></a> | |
<h2>{{album.album}}</h2> | |
<p>{{album.date}}</p> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment