Reputation: 700
I use select2 from angular-ui, everything works ok, but it passes to ng-model object and I need to get plain value
this is in controller
$scope.units = {
createSearchChoice:function(term, data) {
if ($(data).filter(function() {
return this.text.localeCompare(term) === 0; }).length===0) {
return {id:term, text:term};
}
},
multiple: false,
data: [{id: 0, text: 'kg'},{id: 1, text: 'ks'},{id: 2, text: 'm'}, {id: 3, text: 'h'}]
};
and this in view
<input type="hidden" class="form-control" id="unit_name" ui-select2="units" ng-model="newItem.unit">
but result is {id: 0, text: 'kg'} and I would need only text from that object. I know that is is possible to get it with .val(), but I not able to use with angular... So how to format output? Is it possible? Thanks
Upvotes: 1
Views: 333
Reputation: 1439
I also have this problem, and i got solution by remove some line of code from the select2-ui.js
.
Commnet following code in select2-ui.js
elm.bind("change", function(e) {
e.stopImmediatePropagation();
if (scope.$$phase || scope.$root.$$phase) {
return;
}
scope.$apply(function() {
controller.$setViewValue(
convertToAngularModel(elm.select2('data')));
});
});
Upvotes: 1