Angularjs + restangular, search albums & artists on spotify
I use restangular module to make connections to the spotify API and get search results of Albums and artists.
When i fetch an album or an artist , it is ok. The problem is when i pass params to restangular in order to search for results. restangular converts the symols &
and =
to special characters , and that makes the URL not working
For example i have the below snippet to search for albums/artists:
//I pass : https://api.spotify.com/v1/search?q=album:lo%20artist:lo&type=album,artist
const params = "album:lo+artist:lo&type=album,artist";
Restangular.all(SEARCH_END_POINT).getList({q: params}).then(function(data){
console.log("All ok");
console.log(data[0].name);
}, function(response) {
console.log("Error with status code", response.status);
});
But i get this FALSE URL:
Can somebody tell me how these symbols remain the same &
and =
?
So there are two things wrong here.
Result type : You said getList, the search API doesn't return an Array, it returns an object.
Restangular.one('search') .get({ q: params, type: 'album,artist' }) .then(function (res) { console.log(res); });