Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Angular & textangular typeahead example:
//I've changed the typeahead to iterate over an array - this is the __only__ way it'll work with textangular,
// Textangular does string manipulation upon select, and cannot work with objects
//viewvalue is http://stackoverflow.com/questions/17837007/in-the-angularjs-bootstrapui-typeahead-whats-viewvalue
// ng-click should probably be typeahead-on-select()
<input data-text-angular data-ng-model="field.name" data-ng-click="itemClicked($index)" name="{{field.caption}}" data-ta-target-toolbars='toolbar' typeahead='option for option in getOptions(field.options) | filter:$viewValue'></input>
//this converts the object to an array, should be self explanatory.
// It's a really good idea to keep you logic _out of_ the html - this increases testability
$scope.getOptions = function(options) {
var arr = []
options.forEach(function(object) {
for (var key in object) {
arr.push(object[key]);
}
})
console.log(arr)
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.