【问题标题】:Auto complete not working it is throwing an error iElement.autocomplete is not a function自动完成不工作它抛出一个错误 iElement.autocomplete 不是一个函数
【发布时间】:2014-03-24 10:59:19
【问题描述】:

我正在尝试使用 Angularjs 在搜索文本框上构建自动完成功能。但收到错误 iElement.autocomplete 不是函数。

代码

  <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);
        };
    }
});

谁能告诉我我想念什么?我也尝试过 datalist html5 标记来自动完成,但它在 IE8 上不起作用。所以我放弃了这种方法。如果有人有更好的自动完成方法,请分享。

【问题讨论】:

    标签: javascript jquery angularjs angularjs-directive


    【解决方案1】:

    它不会工作,因为 IE8 不支持 HTML5,而且在当前版本的 angularjs 中,他们已经放弃了对 IE8 的支持。 Check here.

    【讨论】:

    • @jayaram..你有更好的跨浏览器兼容的自动完成方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 2014-09-05
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多