2014-03-24 2 views
0

Angularjs를 사용하여 검색 텍스트 상자에 자동 완성 기능을 구현하려고합니다. 하지만 오류가 발생하면 iElement.autocomplete는 함수가 아닙니다.자동 완성 기능이 작동하지 않습니다. 오류가 발생합니다. 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: "[email protected]" 
     }, 
     { 
     value: "manu123", 
     email: "[email protected]" 
     } 
    ]; 
    $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에서는 작동하지 않았다. 그래서 나는이 접근법을 떨어 뜨린다. 누구든지 자동 완성을위한보다 나은 접근법을 가지고 있다면 공유하라.

답변

2

IE8은 HTML5를 지원하지 않으며 현재 버전의 angularjs에서도 IE8에 대한 지원을 중단했습니다. Check here.

+0

@ jayaram..do 크로스 브라우저와 호환되는 자동 완성을위한 더 나은 접근법이 있습니까? – sar

+0

IE에서 수정 사항을 보려면 https://github.com/es-shims/es5-shim을 사용해보십시오. –

+0

이것도 봐 https://github.com/angular-ui/bootstrap/issues/181 –

관련 문제