Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Last active September 7, 2016 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/da8575a414da7419b262eda43dc28ec2 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/da8575a414da7419b262eda43dc28ec2 to your computer and use it in GitHub Desktop.
An AngularJS controller that makes requests to api.sr.se
var myApp = angular.module('myApp', []);
myApp.controller('SRChannelsController', ['$scope', '$http', function($scope, $http) {
$scope.header = 'Radio channels on Sveriges Radio';
$scope.filter = "Riks";
$scope.filterChanged = function() {
getChannelsInfo($scope.filter);
};
getChannelsInfo = function(filter) {
var promise = $http.get("http://api.sr.se/api/v2/channels/?format=json&pagination=false&filter=channel.channeltype&filtervalue=" + filter);
promise.then(function(response) {
var channels = response.data.channels;
$scope.channels = channels;
});
};
getChannelsInfo($scope.filter);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment