var mainCtr = function($scope, $http){ $scope.doSearch = function(){ var uri = "http://search.twitter.com/search.json?q=" + $scope.query + '&callback=JSON_CALLBACK'; $http.jsonp(uri).success(function(data){ console.dir(data.results); $scope.results = data.results; }); } }
<!DOCTYPE html> <html lang="ja" ng-app> <head> <meta charset="UTF-8"> <title>Angularの練習</title> <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script> <script src="myscript.js"></script> </head> <body> <h1>Twitter Search</h1> <div ng-controller="mainCtrl"> <form ng-submit="doSearch()" name="myForm"> <input type="text" ng-model="query" required> <input type="submit" value="search" ng-disabled="myForm.$invalid"> </form> <h2>Result</h2> <ul> <ul ng-show="results.length"> <li ng-repeat="result in results"> <img ng-src="{{result.profile_image_url}}"> <a ng-href="http://twitter.com/{{result.from_user}}/status">{{result.text}}</a> ({{result.from_user}}) </li> </ul> <p ng-hide="results.length">↑から検索してください</p> </div> </body> </html>