【问题标题】:autocomplete jquery element.autocomplete is not a function自动完成 jquery element.autocomplete 不是一个函数
【发布时间】:2016-08-16 23:43:31
【问题描述】:

Js 将文件导入我的项目,也尝试从官方网站 url 进行但不工作。

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

这似乎很奇怪,在我看到的所有关于此功能的示例中都发生了与我所做的相同的事情,但错误对我来说仍然存在。 我添加指令和工厂以在 angularjs + ionic 中工作

.factory('autoCompleteDataService', [function() {
return {
    getSource: function() {
        //this is where you'd set up your source... could be an external source, I suppose. 'something.php'
        return ['apples', 'oranges', 'bananas'];
    }
}
}])

.directive('autoComplete', function(autoCompleteDataService) {
return {
    restrict: 'A',
    link: function(scope, elem, attr, ctrl) {
                // elem is a jquery lite object if jquery is not present,
                // but with jquery and jquery ui, it will be a full jquery object.
        elem.autocomplete({
            source: autoCompleteDataService.getSource(), //from your service
            minLength: 2
        });
    }
};
})

<input type="text" ng-model="foo" auto-complete/>
                  Foo = {{foo}}

但我不断收到此错误。

TypeError: elem.autocomplete is not a function
at link (file:///Users/lixsys/app_view/www/js/app.js:203:18)
at invokeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:16911:9)
at nodeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:16421:11)
at compositeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:15770:13)
at compositeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:15773:13)
at compositeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:15773:13)
at nodeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:16416:24)
at compositeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:15770:13)
at compositeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:15773:13)
at nodeLinkFn (file:///Users/lixsys/app_view/www/lib/ionic/js/ionic.bundle.js:16416:24) <input type="text" ng-model="foo" auto-complete="" class="ng-pristine ng-untouched ng-valid">

【问题讨论】:

    标签: jquery angularjs autocomplete


    【解决方案1】:

    请检查一下,

    http://jsfiddle.net/swfjT/2884/

    问题是需要调用控制器

     <div ng-app='MyModule'>
        <div ng-controller='DefaultCtrl'>
            <input type="text" ng-model="foo" auto-complete/>
                      Foo = {{foo}}
        </div>
    </div>
    
    
        angular.module('MyModule', []).controller('DefaultCtrl',['$scope', function($scope) {}])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2016-02-25
      • 1970-01-01
      • 2022-06-25
      • 2018-07-11
      • 1970-01-01
      相关资源
      最近更新 更多