Skip to content

Instantly share code, notes, and snippets.

@efatsi
Created November 16, 2012 22:41
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 efatsi/4091578 to your computer and use it in GitHub Desktop.
Save efatsi/4091578 to your computer and use it in GitHub Desktop.
Angular.js twitter search
<!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>
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