一尘不染

文本框中的建议可能吗?

angularjs

我有一个带有文本类型的输入框:

<input type="text></input>

我有一个名字列表:

 $scope.employees = [{
    name: "vishnu"
 }, {
    name: "seenu"
 }];

现在让它只有2。当我键入时v,它应该显示vishnu为建议。当我输入se, it should showseeu`作为建议时。如何做到这一点?


阅读 259

收藏
2020-07-04

共1个答案

一尘不染

的填充选项DataList控件与值$scope.employees数据-
NG-重复

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>

祝好运!

2020-07-04