Skip to content

Instantly share code, notes, and snippets.

@borntorun
Last active August 29, 2015 14:19
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 borntorun/7671ef832b7cbacb8255 to your computer and use it in GitHub Desktop.
Save borntorun/7671ef832b7cbacb8255 to your computer and use it in GitHub Desktop.
<div ng-controller="RemotePrefetchCtrl as vm">
<angular-typeaheadjs prefetch="{{vm.prefetch}}"
remote="{{vm.remote}}"
onselected="vm.onSelected"
onclosed="vm.onClosed"
oncursorchanged="vm.onCursorChanged"
datasource="countries"
placeholder="Search for Countries"
minlensugestion="1"
limit="9"
clearvalue="true"
cssinput="inputclass"/>
</div>
angular
.module('appdemo', ['angularTypeaheadjs'])
.controller('RemotePrefetchCtrl', [ '$scope', RemotePrefetchCtrl ]);
function RemotePrefetchCtrl() {
var vm = this;
vm.itemonSelected = [];
vm.prefetch = 'data/countries.json'
vm.remote = 'data/%QUERY.json';
vm.onSelected = function (item) {
for(var i = vm.itemonSelected.length - 1; i >= 0; i--) {
if(vm.itemonSelected[i] === item.name) {
vm.itemonSelected.splice(i, 1);
}
}
vm.itemonSelected.push(item.name);
vm.itemonCursorChanged = '';
};
vm.onCursorChanged = function(item) {
vm.itemonCursorChanged = item.name;
};
vm.onClosed = function() {
vm.itemonCursorChanged = '';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment