Wednesday 15 January 2014

angularjs - ng-model not working with typeahead -



angularjs - ng-model not working with typeahead -

i using angular's typeahead, , running problem ngmodel.

here typeahead html

<input type= "text" ng-model= "symbol" placeholder= "begin typing" typeahead= "hit.message nail in gettypeaheadcontents($viewvalue)" typeahead-loading= "loadingsymbols" typeahead-editable= "false" typeahead-on-select= "onselect($item, $model, $label)" typeahead-min-length= 2 typeahead-wait-ms= 500 class= "form-control" /> <input ng-click= "search()" value= "search!"/>

here code in controller (quite basic time being)

$scope.search = function(){ alert($scope.symbol); }

now, autocomplete code works expected, when click search button, alert message "undefined"

what's weirder tried setting

$scope.symbol = "";

at origin of controller, , when click search button without typing typeahead, empty string alerted me, expected. however, when type typeahead , 1 time again nail search, "undefined" 1 time again. clearly, angular's typeahead not playing nicely ng-model, i'm not sure here.

advice?

don't know if still issue you. i've tried latest release of angularstrap (2.1.4) , got working when set ng-model object on set property.

$scope.selectedpart = {} <input type="text" class="form-control" ng-model="selectedpart.part_id" data-animation="am-flip-x" ng-options="part.value part.name part in parts" placeholder="selecteer onderdeel" bs-typeahead>

somewhere in function (could deep $watch)

console.log($scope.selectedpart.part_id)

angularjs angularjs-scope undefined typeahead angular-ngmodel

No comments:

Post a Comment