5

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

1
  • You don't need any external Js file. Ionic runs on angular JS which has MVC(model, view, controller) model. Codes are run according to the controller linked with respective view. So you need to put your code in Respective controller instead of external JS. So whenever you load a view js is called from respective controller not whole js. Kindly read tutorialspoint.com/angularjs/angularjs_mvc_architecture.htm for more info. Commented Jul 27, 2016 at 13:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.