I'm new to Ionic/AngularJS. I need to display an Image Carousel in a single view, so I need to load in that view the corresponding JS (carousel.js). I don't want to put js file into index.html file, cause it will be loaded in all pages and I only need to use it in particular one.
My question is How I can load this JS in particular view?
Thanks in advance
Add following code in onLoad of page where you want to load js file
<template onLoad="onLoad()"></template>
function onLoad(){
var script = document.createElement("script");
script.src = "https://somejavascript file url";
document.getElementsByTagName("head")[0].appendChild(script);
}
it will be called when particular page or template will be loaded.
Regards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With