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; }; ... }); 我有自动完成工作,但选择回调似乎不能正常工作. 注意:我用this answer作为参考. 解决方法
试试这个,
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl',$http) { ... $scope.onSelect = function ($item,$label) { $scope.$selected = $item; }; ... }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |