AngularJSでGitHubにあるrepositoryのタグ一覧をJSONPで取得して表示するプログラムを作成しました。
$httpでJSONPを行うにはcallback関数名をJSON_CALLBACKにする必要があります。
AngularJSのtag一覧を取得するURLの例
https://api.github.com/repos/angular/angular.js/tags?callback=JSON_CALLBACK
<!doctype html>
<html ng-app="githubApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.19/angular.min.js"></script>
</head>
<body>
<div ng-controller="GitHubController">
<h3>のTag一覧</h3>
repository <input ng-model="repository"><button ng-click="getTags(repository)">Display</button>
<div ng-repeat="d in response.data">
<div>
{{ d.name }}
</div>
</div>
</div>
</body>
</html>
var app = angular.module('githubApp', []);
app.controller('GitHubController', ['$scope', "$http", function($scope, $http) {
var callback = function (response) {
$scope.response = response;
};
var getTags = function(repository) {
$http.jsonp("https://api.github.com/repos/" + repository + "/tags?callback=JSON_CALLBACK")
.success(callback);
$scope.title = repository;
}
$scope.repository = "angular/angular.js";
$scope.title = "angular/angular.js";
$scope.getTags = getTags;
getTags($scope.repository);
}]);