我有一个带文字类型的输入框:
<input type="text></input>
我有一个名单:
$scope.employees = [{
name: "vishnu"
}, {
name: "seenu"
}];
现在让它只有2。
当我输入v
时,它应显示vishnu
作为建议。当我输入se, it should show
seenu`作为建议时。怎么能实现这一目标?
答案 0 :(得分:6)
使用$scope.employees
datalist填充data-ng-repeat的选项:
var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
$scope.employees = [{
name: "vishnu"
},
{
name: "seenu"
}];
});
&#13;
<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>
&#13;
祝你好运!
答案 1 :(得分:0)
下面给出了Jquery自动完成
的简单示例$scope.complete=function(){
$( "#tags" ).autocomplete({
source: $scope.availableTags
});
}
});
答案 2 :(得分:0)
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>