Created
November 16, 2012 22:41
-
-
Save efatsi/4091578 to your computer and use it in GitHub Desktop.
Angular.js twitter search
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="Twitter"> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-resource.min.js"></script> | |
<script type="text/javascript" src="twitter.js"></script> | |
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> | |
</head> | |
<body> | |
<div ng-controller="TwitterCtrl"> | |
<form class="form-horizontal"> | |
<input type="text" ng-model="searchTerm"> | |
<button class="btn" ng-click="doSearch(searchTerm)"><i class="icon-search"></i> Search</button> | |
</form> | |
<table class="table table-striped"> | |
<tr ng-repeat="tweet in twitterResult.results"> | |
<td>{{tweet.text}}</td> | |
</tr> | |
</table> | |
</div> | |
</body> | |
</html> |
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
angular.module('Twitter', ['ngResource']); | |
function TwitterCtrl($scope, $resource) { | |
$scope.twitter = $resource('http://search.twitter.com/:action', | |
{action:'search.json', callback:'JSON_CALLBACK'}, | |
{get:{method:'JSONP'}}); | |
$scope.doSearch = function(toSearch) { | |
$scope.twitterResult = $scope.twitter.get({q:toSearch}); | |
} | |
// default search term | |
$scope.doSearch('jinglebots'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment