var app = angular.module('plunker', ['ngSanitize', 'ui.select']);
app.controller('MainCtrl', function($scope, $http) {
var _this = this;
_this.repo = {};
_this.getRepos = function(keyword){
return $http.get(
' https://api.github.com/search/repositories',
{params: {q: keyword}}
).then(function(response) {
_this.repos = response.data.items
});
}
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.13.2/select.css" />
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular-sanitize.js" data-semver="1.4.8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.13.2/select.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl as vm">
<ui-select ng-model="vm.repo.selected" theme="select2" reset-search-input="false" style="width: 300px;">
<ui-select-match placeholder="Search repos...">
<span class="selected_icon" ng-style="{'background-image':'url(' + vm.repo.selected.owner.avatar_url + ')'}">
</span>
<span class="selected_title">{{vm.repo.selected.full_name}}</span>
</ui-select-match>
<ui-select-choices repeat="repo in vm.repos" refresh="vm.getRepos($select.search)" refresh-delay="500">
<div class="select2-result-repository clearfix">
<div class="select2-result-repository__avatar">
<img ng-src="{{repo.owner.avatar_url}}"></div>
<div class="select2-result-repository__meta">
<div class="select2-result-repository__title">{{repo.full_name}}</div>
<div class="select2-result-repository__description">{{repo.description}}</div>
<div class="select2-result-repository__statistics">
<div class="select2-result-repository__forks">
<i class="fa fa-flash"></i> {{repo.forks}} Forks</div>
<div class="select2-result-repository__stargazers"><i class="fa fa-star"></i> {{repo.starts}} Stars</div>
<div class="select2-result-repository__watchers"><i class="fa fa-eye"></i> {{repo.watchers}} Watchers</div>
</div>
</div>
</div>
</ui-select-choices>
</ui-select>
</body>
</html>
.selected_icon {
height: 25px;
width: 30px;
display: inline-block;
background-size:contain;
background-repeat: no-repeat;
}
.selected_title {
height: 25px;
padding-left: 10px;
display: inline-block;
line-height: 28px;
}
.select2-result-repository {
padding-top: 4px;
padding-bottom: 3px;
}
.select2-result-repository__avatar {
float: left;
width: 60px;
margin-right: 10px;
}
.select2-result-repository__avatar img {
width: 100%;
height: auto;
border-radius: 2px;
}
.select2-result-repository__meta {
margin-left: 70px;
}
.select2-result-repository__title {
color: black;
font-weight: bold;
word-wrap: break-word;
line-height: 1.1;
margin-bottom: 4px;
}
.select2-result-repository__forks,
.select2-result-repository__stargazers {
margin-right: 1em;
}
.select2-result-repository__forks,
.select2-result-repository__stargazers,
.select2-result-repository__watchers {
display: inline-block;
color: #aaa;
font-size: 11px;
}
.select2-result-repository__description {
font-size: 13px;
color: #777;
margin-top: 4px;
}
.select2-results__option--highlighted .select2-result-repository__title {
color: white;
}
.select2-results__option--highlighted .select2-result-repository__forks,
.select2-results__option--highlighted .select2-result-repository__stargazers,
.select2-results__option--highlighted .select2-result-repository__description,
.select2-results__option--highlighted .select2-result-repository__watchers {
color: #c6dcef;
}
.clearfix {
clear: both;
}