Ionic: ReferenceError: $ is not defined

2019-08-12 07:57发布

I'm getting the error ReferenceError: $ is not defined on my ionic application.

I'm trying to open links in the systems browser from my json file.

Here's the code:

  $timeout(function () {
   $('.ex-link').click(function () {
     var url = $(this).attr('href');
     window.open(encodeURI(url), '_system', 'location=yes');
     return false;
   })
})

Line which gets the error is:

$('.ex-link').click(function () {

1条回答
可以哭但决不认输i
2楼-- · 2019-08-12 08:13

Angular will use jqLite. However you can include jQuery.js before Angular.js and make Angular replace jqLite by jQuery. $ will be difined.

Include jQuery before including AngularJS as,

<!-- Add jQuery from -->
<script type="text/javascript" src="jquery.js"></script>

<!-- And then AngularJS -->
<script type="text/javascript" src="angularjs.js"></script>
查看更多
登录 后发表回答