文本框中的建议可能吗? [英] Suggestion in text box possible?
本文介绍了文本框中的建议可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本输入框:
现在让它只有 2 个.当我输入 v
时,它应该显示 vishnu
作为建议.当我输入 se 时,它应该显示
seenu` 作为建议.如何做到这一点?
解决方案
填充 datalist 的选项$scope.employees
和 data-ng-repeat:
var app = angular.module('myApp', []);app.controller('myController', function($scope, $http) {$scope.employees = [{名称:毗湿奴"},{名称:seenu"}];});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="myApp" ng-controller="myController"><input type="text" list="names" placeholder="选择一个名字.."><datalist id="names"><option data-ng-repeat="员工中的项目" value="{{item.name}}"></数据列表>
祝你好运!
I have a input box with type text:
<input type="text></input>
I have a list of names:
$scope.employees = [{
name: "vishnu"
}, {
name: "seenu"
}];
Now let it be only 2.
When I type v
, it should show vishnu
as suggestion. When I type se, it should show
seenu` as suggestion. How can this be achieved?
解决方案
Populate options of datalist with values in $scope.employees
with data-ng-repeat:
var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
$scope.employees = [{
name: "vishnu"
},
{
name: "seenu"
}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
<input type="text" list="names" placeholder="Pick a name..">
<datalist id="names">
<option data-ng-repeat="item in employees" value="{{item.name}}">
</datalist>
</div>
Good Luck!
这篇关于文本框中的建议可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文