I want to execute a method when my $http.selectedSong (model value) changes , but I can't seem to let it work anny ideas how this comes? :
app.controller('songController', ['$http', function($http) {
$songs = this;
$songs.tracks = [];
$http({
url: "http://api.q-music.be/1.2/tracks/plays?limit=20",
dataType: "jsonp",
jsonp: "callback"
})
.success(function(lastSongsList) {
$http.$watch('selectedSong', function (newVal, oldVal) {
if (newVal !== oldVal) {
alert('hej');
}
});
});
}]);
My goal is to work with data i achieved from this html code :
<select ng-model="selectedSong" ng-init="selectedSong === songs.tracks[0].title" ng-options="song as song.title for song in songs.tracks"></select>
I want to see when the value I select in 'select' changes so i can work with this value to do methods etc ...
selectedSong. And$httpdoesn't have a$watchfunction. I suspect you want to do something when the HTTP request comes back? Then the success callback is all you need.ng-change