I am building an application with the Spotify API. the application can do: 1. Find albums by artist name through the input field 2. After the albums are shown, the user can click on the album name and see the tracks of this album
I created 2 views: 1. view albums 2. View tracks, view child albums.
I would like to show the ui-view tracks of a particular clicked album - with ID - into ng-repeat albums. but the result is that I have the same list of tracks by click on the entire list of albums. how can I show the ui-view landscape track in a container with a click that is the result of the ng-repeat directive?
here is the code:
Route:
------ .config(function ($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/'); $stateProvider .state('albums', { url: '/', templateUrl: 'views/main.html', controller: 'MainCtrl' }). state('albums.tracks', { url: ':id/tracks', templateUrl: 'views/tracks.html', controller: 'TracksCtrl' }); }) -----
Browse Albums:
<div ng-if="albums.items"> <h1>{{searchedArtist}} Album List:</h1> <div ng-repeat="album in albums.items | unique:'name'" id="{{album.id}}"> <img ng-src="{{album.images[1].url}}" width="100"> <a ui-sref="albums.tracks({id : album.id})">{{album.name}}</a> <div ui-view></div> </div>
Main Album Controller:
angular.module('spotifyAngularApp') .controller('MainCtrl', function ($scope, spotifyService) { var options = { 'limit': 10 }; $scope.searchAlbums= function () { var sanitizeArtist = $scope.artist.split(' ').join('+'); $scope.searchedArtist = $scope.artist; spotifyService.search(sanitizeArtist, 'album', options).then(function(data) { $scope.albums = data.albums; }); }; });
Track Controller:
angular.module('spotifyAngularApp') .controller('TracksCtrl', function ($scope, $stateParams, spotifyService) { console.log($stateParams); spotifyService.albumTracks($stateParams.id).then(function(data){ $scope.tracks = data.items; }); });
javascript angularjs nested angularjs-ng-repeat angular-ui-router
davelab
source share