加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 从类型选择中更新模型

发布时间:2020-12-17 06:58:19 所属栏目:安全 来源:网络整理
导读:请考虑我的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" t
请考虑我的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>

条目填充在其他地方.然后在控制器中:

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

我有自动完成工作,但选择回调似乎不能正常工作.
我希望{{selection_made}}能够显示所选的内容,而是呈现文字文本{{selection_made}}.为什么?我错过了什么?

注意:我用this answer作为参考.

解决方法

试试这个,

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读