Created
March 27, 2014 10:38
-
-
Save jacoyutorius/9804705 to your computer and use it in GitHub Desktop.
Angular.jsでカーリルAPIを叩いてみました
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app> | |
<head> | |
<title>LibrarySearchSample</title> | |
<script type="text/javascript" src="http://code.angularjs.org/angular-1.0.0.min.js"></script> | |
</head> | |
<body ng-controller="LibrarySearchCtrl" ng-init="init()"> | |
<a class="navbar-brand" href="#">LibrarySearchSample</a> | |
<form class="navbar-form navbar-left" role="search" ng-submit="doSearch()" action=""> | |
<div class="form-group"> | |
<input type="text" class="search-query" placeholder="Search" ng-model="query"> | |
</div> | |
</form> | |
<div class="container"> | |
<div ng-repeat="result in results"> | |
<div class="row"> | |
<div class="panel panel-primary" style="text-align:center;"> | |
<div> | |
<h4><a href="{{result.url_pc}}">{{result.formal}}</a></h4> | |
</div> | |
<address> | |
{{result.address}} <br> | |
<abbr title="Phone">TEL:</abbr>{{result.tel}} <br> | |
</address> | |
</div> | |
</div> | |
</div> | |
<div class="message"> | |
<div class="alert alert-danger"> | |
<h4> | |
{{message}} | |
</h4> | |
</div> | |
</div> | |
</div> | |
<script> | |
var API_KEY = "YOUR_API_KEY" | |
function PositionCallback($scope, $http, pref){ | |
console.log("query by " + pref); | |
var uri = "http://api.calil.jp/library?appkey=" + API_KEY | |
+ "&format=json" | |
+ "&pref=" + encodeURI(pref) | |
+ "&callback=JSON_CALLBACK"; | |
console.log(uri); | |
$http.jsonp(uri).success(function(data){ | |
$scope.results = data; | |
}); | |
} | |
function BookSearch(systemid){ | |
var url = "http://api.calil.jp/check?appkey=" + API_KEY | |
+ "&format=json" | |
+ "&systemid=" + systemid | |
+ "&callback=JSON_CALLBACK"; | |
} | |
function LibrarySearchCtrl($scope, $http){ | |
$scope.doSearch = function(){ | |
console.log($scope.query); | |
$scope.message = ''; | |
PositionCallback($scope, $http, $scope.query); | |
}; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment