自动完成不工作,抛出错误元素.自动补全不是一个功能

Auto complete not working it is throwing an error iElement.autocomplete is not a function

本文关键字:功能 一个 错误元素 工作      更新时间:2023-09-26

我正在尝试使用Angularjs构建一个自动完成搜索文本框。而是得到一个错误元素。自动补全不是一个功能

代码
  <body ng-controller='FriendController'>
  <form ng-submit="addFriend()">
 <input type="email" auto-complete ui-items="fbFriends" ng-model="friend" autofocus />
</form>
<ul ng-repeat="friend in friends">
  <li>
    {{friend.text}}
  </li>
</ul>
<script>
   var addFriendAppModule = angular.module('addFriendApp', []);
   addFriendAppModule.controller('FriendController',
    function($scope) {
      var friendArr = [];
    $scope.fbFriends = [
         {
          value: "manu", 
          email: "sept@gmail.com"
        },
        {
        value: "manu123", 
        email: "sept123@gmail.com"
        }
    ];
    $scope.friends = friendArr;         
    $scope.friend = '';
    $scope.addFriend = function() {
        var newFriend = $scope.friend.trim();
        if (newFriend.length === 0) {
            return;
        }
        friendArr.push(
            {text: newFriend}
        );
    };      
});
addFriendAppModule.directive('autoComplete', function($timeout) {
    return function(scope, iElement, iAttrs) {
        iElement.autocomplete({
            source: scope[iAttrs.uiItems],
            focus: function(event,ui) {
                iElement.val(ui.item.email);
                return false;
            },
            select: function(event, ui) {
                    iElement.val(ui.item.email);
                    return false;
                  //  iElement.trigger('input');
                   // iElement.trigger('submit');
            }
        }).data("autocomplete")._renderItem = function(ul, item) {
            return $("<li></li>")
                .data( "item.autocomplete", item )
                .append(item.email)
                .appendTo(ul);
        };
    }
});

谁能告诉我我错过了什么?我也尝试过数据主义者html5标签的自动完成,但它没有在IE8上工作。所以我放弃了这个方法。如果有人有更好的自动补全方法,请分享。

它不能工作,因为IE8不支持HTML5,而且在当前版本的angularjs中,他们已经放弃了对IE8的支持。检查在这里。