Updating the model from a typeahead-on-select

匆匆过客 提交于 2019-12-12 10:47:55

问题


Consider the following in the body of my html file:

<html>
...
<body>
...
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<input type="text" ng-model="selected" typeahead="name as entry.name for entry in entries | filter:{name: $viewValue} | limitTo:8" 
                 typeahead-on-select='onSelect($item, $model, $label)'
                 class="form-control">

{{selection_made}}
</div>
<body>
</html>

where entries are populated somewhere else. And then this in the controller:

angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {
        ...
        $scope.onSelect = function ($item, $model, $label) {
                $scope.$selection_made = $item;
        };
...
});

I have the autocomplete working, but the selection callback doesn't seem to work well. I was expecting {{selection_made}} to display whatever is selected, but instead the literal text {{selection_made}} gets rendered. Why? What am I missing?

Note: I used this answer for reference.

来源:https://stackoverflow.com/questions/27365371/updating-the-model-from-a-typeahead-on-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!