Last active
August 29, 2015 14:06
-
-
Save josephfinlayson/f912cde04b0fdfb25710 to your computer and use it in GitHub Desktop.
Angular & textangular typeahead example:
This file contains hidden or 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
//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