NyaO
February 15, 2017, 1:34pm
1
How to install and use jquery in ionic 2? I use ionic documentation for using third party libs for it.
I have followed these steps:
npm install @types /jquery --save - it is OK
npm install @types /jquery-mask-plugin --save - it is OK
Add in declarations.d.ts file:
declare module ‘jquery’;
declare module ‘jquery-mask-plugin’;
But when I try to compile app, I got a Error:
Runtime Error
Cannot find module "jquery"
In tsconfig file:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
What is wrong?
If you describe your actual goal, I bet somebody here can help you achieve it using Angular instead of jQuery.
Vadillo
February 15, 2017, 9:00pm
3
I think that the problem is similar than this:
Hi @Vadillo - I solved my problem by using the library the old fashioned JavaScript way.
Since the “import” of my library was not working I just declared the namespace variable as global (i.e. after all the imports and before your TypeScript @Component or other class starts). Then I used that variable in the code. This of-course will work if the library is available globally, in my case it was.
Example code snippet:
//Start of imports
import { ... } from '...';
//End of imports
declare var v…
NyaO
February 16, 2017, 8:41am
4
Sorry for my bad English. I just had to edit the post for any readability.
My actual is that I want to use jQuery in my project and use typed first party lib named jquery-mask-plugin. I was read the documentation for it, but I got a Error in declarations file.
NyaO
February 16, 2017, 8:52am
5
I was tried this solution it is not the same and not solved my problem. I think if you will follow my steps you will get the same Error.
Have you looked at angular2-text-mask ?
NyaO
February 16, 2017, 9:56am
7
Sure. It is works fine but, not for my case. I need to give to my users any chance to set any mask on field with phone.
It can be:
+7 (999)999-99-99
or
+1(999)999-99-99
or
999-99-99
and etc.
So it must be what ever they want.
angular2-text-mask can only use fixed masks. That’s why I want to use other libs. Do you can help me?