Embedding a custom JS file in an ion project

I am new to Ionic / AngularJS. I need to display Image Carousel in one view, so I need to load the corresponding JS (carousel.js) in this view. I do not want to put the js file in the index.html file, because it will be loaded on all pages, and I will need to use it, in particular, one.

My question is: how can I load this JS in a specific view?

Thank you in advance

+5
source share
1 answer

Add the following code to the onLoad page where you want to load the 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 a particular page or template is loaded.

Sincerely.

+1
source

All Articles