Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在选择时从typeahead更新模型_Angularjs_Angular Ui Bootstrap - Fatal编程技术网

Angularjs 在选择时从typeahead更新模型

Angularjs 在选择时从typeahead更新模型,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,在我的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} | limitT

在我的
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>
我有自动完成功能,但是选择回调似乎不太好用。 我希望
{{selection\u made}}
显示所选的内容,但是文本
{{selection\u made}}}
会呈现出来。为什么?我错过了什么


注意:我用于参考。

谢谢@Satpal,是的,如果您将调试器放在$scope.selection\u made=$item上面,我尝试了,但没有运气(我得到了完全相同的结果);行,然后检查项目、模型和标签。它们包含了你所期望的信息吗?@KreepN是的,我刚检查过,确实如此。除了模型,它似乎是“未定义的”。非常感谢@KreepN。。。。你用调试器给我指明了正确的方向。问题是我在做
$scope.$selection\u made=$item
(我用过)。将内容更改为
$scope.selection\u made=$item
修复了所有问题。ThanksAngular UI实际上需要语法:$scope.$[variablename]。在您的例子中,如果您将{{selection_made}}更改为{{$selection_made}},并将onSelect代码保留在您的问题中的方式,那么它就会工作。
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {
        ...
        $scope.onSelect = function ($item, $model, $label) {
                $scope.$selection_made = $item;
        };
...
});