Where to include js libraries in Ionic?

thank you for your time! I fight to run any scripts in the Ion Framework sidemenu starter template. I placed them everywhere (except where they should be, clearly), but to no avail. I tried loading them before ionic, as well as using a lower version of jquery. I built a decent jquery mobile site that I passed through the handset and it works fine, but I would like to use Ionic as a personal call. However, I cannot get any scripts that I use to work.

Do I include them in the main index file, and if so, do they load when I create each template? Or should I include them in each of the templates? If you can be specific enough about where in the folders I should place them (if there really is a certain place), and also where I should call the scripts.

I installed ion using this yoma generator https://github.com/diegonetto/generator-ionic if that helps.

If I noticed that I was clear enough, comment on this and I will continue in more detail.

Thanks for your patience - J

+5
source share
3 answers

I know this is old, but for those struggling with this for Ionic 2, add the script files to src / assets / scripts and then access them through the script tag in src / index.html (and not www). When it is created, everything in src / assets will be copied to www / assets, including your scripts. index.html will also be copied to www.

<!-- cordova.js required for cordova apps --> <script src="cordova.js"></script> <script src="assets/scripts/openpgp/openpgp.js"></script> <script src="assets/scripts/openpgp/openpgp.worker.js"></script> 
+14
source

I would add any scripts, such as jquery, either immediately before or immediately after the script tag for the cord. This is in index.html , located in the app/ project directory in which the yoman generator is created.

 <!-- Place scripts such as JQuery here --> <!-- cordova script (this will be a 404 during development) --> <script src="cordova.js"></script> <script src="scripts/config.js"></script> <script src="scripts/app.js"></script> <script src="scripts/controllers.js"></script> 

Once you have placed the scripts here, they will be called when the application starts, and libraries such as jquery will be available worldwide in the application. Hope this helps.

+6
source

As well indicated by the user here https://github.com/ionic-team/ionic/issues/9422

  1. Install the latest ionic
  2. Start your project
  3. Go to / src /
  4. open the asset folder
  5. create folder / js / inside assets
  6. copy your .js to this js folder
  7. goto / src / index.html
  8. Add your way
  9. Go to your typescript file of your choice and declare var N;
  10. N.yourFunction
  11. ion feed
0
source

Source: https://habr.com/ru/post/1205232/


All Articles