Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use jquery in ionic 3

I'm trying to load external website in a div using jquery in ionic 3.

TS:

export class HomePage 
{
  constructor(public navCtrl: NavController) {    
      $('#loadExternalURL').load('http://www.google.com');
  }
}

HTML:

<ion-content>
    <div id="loadExternalURL"></div>
</ion-content>

I'm getting blank screen on serving the ionic app. Is there anything I'm missing? Any Suggestion?

like image 806
Dominic Francis Avatar asked Nov 27 '22 13:11

Dominic Francis


1 Answers

I did it in following way,

  1. Install Jquery module in your IONIC-3 app,

    npm install jquery --save

  2. Import JQuery in HomePage.ts

    import * as $ from "jquery";

  3. Use $ to call jquery methods.

I wait for method ngAfterViewInit to make sure view is initialized.

ngAfterViewInit(){
    $(document).ready(function(){
        alert('JQuery is working!!');
    });
}
like image 88
pgcan Avatar answered Nov 30 '22 23:11

pgcan