javascript 在 Ionic index.html 中包含 jQuery 的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28932096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to include jQuery in Ionic index.html
提问by Sam
I have a strange problem here.
我这里有一个奇怪的问题。
I am working on a Ionic (AngularJS) project and using jQuery in one of my controllers, so need to add the reference to it in index.html
我正在处理一个 Ionic (AngularJS) 项目并在我的一个控制器中使用 jQuery,因此需要在 index.html 中添加对它的引用
If I add reference like this -
如果我添加这样的参考 -
<!-- jQuery js -->
<script type="text/javascript" src="lib/jquery/jquery-2.1.3.min.js"></script>
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
then, I get below error from one of the views -
然后,我从其中一种观点中得到以下错误 -
Error: [$compile:ctreq] Controller 'ionTabs', required by directive 'ionTabNav', can't be found!
But, If I add reference like this -
但是,如果我添加这样的参考 -
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- jQuery js -->
<script type="text/javascript" src="lib/jquery/jquery-2.1.3.min.js"></script>
then, I get below error from another one of the controllers, which was the reason I included jQuery in the first place -
然后,我从另一个控制器得到以下错误,这就是我首先包含 jQuery 的原因 -
Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite!
Not sure how to resolve this? I need to get both functionalities working.
不知道如何解决这个问题?我需要让这两个功能都正常工作。
Thanks in advance.
提前致谢。
回答by lwalden
Looks like this is a conflict between ionic and certain versions of jQuery . https://github.com/driftyco/ionic/issues/1976- switching the version of jQuery you are using should resolve.
看起来这是 ionic 和某些版本的 jQuery 之间的冲突。https://github.com/driftyco/ionic/issues/1976- 切换您正在使用的 jQuery 版本应该可以解决。
回答by Mark Conroy
I have a feeling that the problem here is not with a conflict between ionic (per se) and jQuery, but an issue with Angular and jQuery.
我有一种感觉,这里的问题不是离子(本身)和 jQuery 之间的冲突,而是 Angular 和 jQuery 的问题。
Angular comes with a jQlite version of jQuery and that's probably what is conflicting. You might get some more information from this post on the Ionic Forum.
Angular 附带了一个 jQlite 版本的 jQuery,这可能是冲突的地方。您可能会从Ionic 论坛上的这篇文章中获得更多信息。
Sorry I can't be more helpful, I'm only just starting out on my ionic adventures myself.
对不起,我不能提供更多帮助,我自己才刚刚开始我的离子冒险。
回答by Michel Arteta
You need to use jQuery Lite. Read more at https://docs.angularjs.org/api/ng/function/angular.element
您需要使用 jQuery Lite。在https://docs.angularjs.org/api/ng/function/angular.element阅读更多