请考虑我的html文件正文中的以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
在哪里entries填充其他地方.然后在控制器中:
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {
...
$scope.onSelect = function ($item, $model, $label) {
$scope.$selection_made = $item;
};
...
});
Run Code Online (Sandbox Code Playgroud)
我有自动完成工作,但选择回调似乎不能正常工作.我希望{{selection_made}}显示所选的任何内容,而是{{selection_made}}呈现文字文本.为什么?我错过了什么?
注意:我用这个答案作为参考.