I am trying to load jQuery into my ionic-angular mobile app project. I installed the node modules via npm and now I’m trying to load jQuery (and signalR) from the index.html file using this:
I don’t use jQuery in any of my Ionic pages. I only need it for signalR to work and I use signalR in a signalr.service.ts file this way:
this.window.$.signalR.connectionState.
When I build with --prod, I get the white screen of death. Using Chrome Debugger connected to my Android device, when I run ionic cordova run android --device --prod I get the following error messages:
Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///android_asset/www/node_modules/signalr/jquery.signalR.js
Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///android_asset/www/node_modules/jquery/dist/jquery.js
Uncaught Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.
ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
ERROR
vendor.js:1
Error: Uncaught (in promise): TypeError: Cannot read property '$' of undefined
TypeError: Cannot read property '$' of undefined
at new n (file:///android_asset/www/build/main.js:1:195806)
at Ne (file:///android_asset/www/build/vendor.js:1:22870)
at Ie (file:///android_asset/www/build/vendor.js:1:22589)
at je (file:///android_asset/www/build/vendor.js:1:22486)
at t.get (file:///android_asset/www/build/vendor.js:1:111915)
at dn (file:///android_asset/www/build/vendor.js:1:29231)
at hn (file:///android_asset/www/build/vendor.js:1:28074)
at an (file:///android_asset/www/build/vendor.js:1:26329)
at Gn (file:///android_asset/www/build/vendor.js:1:40820)
at zn (file:///android_asset/www/build/vendor.js:1:39656)
Don’t. Either find another way to do what you want, or wait until Ionic 4 detaches itself from Angular, because then you might have more jQuery options.
I’m not really using any jQuery commands/functionality in any of my Ionic pages. I only need it for signalR to work. The error is coming from vendor.js file after I do a build.
Importing import jQuery doesn’t help me much since I never use
login(){
$.post(“http://localhost/apps/?apiKey=dev&apiID=login”, $(’#login-form’).serialize(),
function(data, status){
var msg = JSON.parse(data)
if (msg.status == 404){
alert(msg.message);
}else{
this.closeModal(); <====================== this cant across from Jquery to TS function
}
}
)