2017-04-17 58 views
1

我在自動填充中遇到錯誤。如何解決自動完成中的錯誤?

JS:

angular.module('MyModule', []) 
.controller('myCtrl', function ($scope) { 
    $scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", 
    "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", 
    "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", 
    "edouard", "benoit", "guillaume", "nicolas", "joseph"]; 
    }) 
.directive('autoComplete', function ($timeout) { 
    return function (scope, iElement, iAttrs) { 
    iElement.autocomplete({ 
     source: scope[iAttrs.uiItems], 
     select: function() { 
      $timeout(function() { 
       iElement.trigger('input'); 
      }, 0); 
     } 
    }); 
}; 
}); 

HTML:

<div ng-app='MyModule'> 
    <div ng-controller='myCtrl'> 
     <input auto-complete ui-items="names" ng-model="selected"> 
     selected = {{selected}} 
    </div> 
</div> 

我得到下面的屏幕截圖中所示的錯誤: enter image description here

任何幫助,將不勝感激。

+0

嘗試$(iElement).autocomplete(...) –

+0

嘗試更新您的return語句如下 回報{ 限制: 'A', 要求: 'ngModel', 鏈接:功能(範圍,iElement,iAttrs){ iElement.autocomplete({ 來源:姓名, 選擇:函數(){$ 超時(函數(){ iElement.trigger( 'input'); },0); } }); } – CrazyMac

+0

iElement沒有自動完成功能。也許你可以用$(jquery)包裝它 –

回答

0

這裏是工作的例子可以幫助你

<div ng-app='MyModule'> 
    <div ng-controller='DefaultCtrl'> 
     <input complete ng-model="selected"> 
     selected = {{selected}} 
    </div> 
    </div> 

    angular.module('MyModule', []).directive('complete', function($timeout) { 
    var names = ["john", "James", "Raj"]; 

    return function(scope, iElement, iAttrs) { 
      iElement.autocomplete({ 
       source: names, 
       select: function() { 
        $timeout(function() { 
         iElement.trigger('input'); 
        }, 0); 
       } 
      }); 
    }; 
}); 
相關問題