Where to include js libraries in Ionic?

前端 未结 3 2011
旧时难觅i
旧时难觅i 2021-01-12 22:38

thanks for your time! I am battling to get any scripts running in the Ionic framework\'s sidemenu starter template. I have placed them everywhere (except where they\'re supp

相关标签:
3条回答
  • 2021-01-12 22:41

    I know this is old, but for those who are struggling with this for Ionic 2, add script files to src/assets/scripts, then refer to them via a script tag in src/index.html (not the one in www). When it builds, 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>
    
    0 讨论(0)
  • 2021-01-12 22:47

    I would add any scripts such as jquery either just before or just after the script tag for cordova. This is in index.html located within the app/ directory of the project that running the yeoman generator 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 get called when the app runs, and libraries such as jquery will be available globally throughout the app. I hope this helps.

    0 讨论(0)
  • 2021-01-12 22:54

    As nice listed by a user here https://github.com/ionic-team/ionic/issues/9422

    1. Install latest ionic
    2. Start your project
    3. Go to /src/
    4. open the assets folder
    5. create a /js/ folder inside assets
    6. copy your .js inside this js folder
    7. goto /src/index.html
    8. Add your path
    9. Go to your typescript file of choice and declare var N;
    10. N.yourFunction
    11. ionic serve
    0 讨论(0)
提交回复
热议问题