Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject custom JS file in ionic project

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

like image 987
jardila Avatar asked Nov 10 '22 07:11

jardila


1 Answers

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.

like image 128
Hardik Vaghani Avatar answered Nov 15 '22 04:11

Hardik Vaghani