I have been given some JQuery code that I need to use with my ionic 2 project. How can I include it and the JQuery library?
The code looks like this (this is just a
Updated at: 12/04/2018
1. First of all, install jQuery in your ionic project:
$ npm install jquery --save
2. After that, install jQuery global derectory to typings (so you can import it):
$ npm install @types/jquery
3. Then, you can import JQuery in the page/component where you want to use it (for example: home.ts), with the following code:
import * as $ from 'jquery'
And that's all, now it should be working.
Checking:
To check if it worked , you can simply try the following:
1. In your component/page (for example: home.html) add an element with an specific id (in this case: myButton), and a method:
<button id="myButton" (click)="changeTextColor()">Click Me!</button>
2. In your component/page: (in this case: home.ts) add the method:
changeColor(){
$('#myButton').text('white');
}
And that should change the text of the button.