cancel
Showing results for 
Search instead for 
Did you mean: 

How to add external js file in component.js ?

dilna_tp
Explorer
0 Kudos
3,460

Hi,

Iam working in sap ui5 , i am facing problem while adding the external js file in component.js .But its not finding the files.

Below shows the folder structure

jQuery.sap.includeScript("sap/ui/demo/masterdetail/util/Utility");

jQuery.sap.includeScript("sap/ui/demo/masterdetail/util/JOB");

jQuery.sap.includeScript("sap/ui/demo/masterdetail/util/globalvariables");

jQuery.sap.includeScript("sap/ui/demo/masterdetail/util/DecodeWorker");

jQuery.sap.includeScript("sap/ui/demo/masterdetail/util/exif");

As shown above i am trying to add thes files externally. I am getting an error as shown below.

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor
0 Kudos

encapsulate the external js as module

example: JOB.js

jQuery.sap.declare(''nampace.JOB')

//PUT YOUR JOB.JS CODE HERE

when u want to use it

  1. sap.ui.define([ 
  2.     "sap/ui/core/UIComponent", 
  3.     "sap/ui/Device", 
  4.    
  5.     "namespace/JOB" 
  6.     
  7. ], function(UIComponent, Device, JOB) { 
Former Member
0 Kudos

you can load it in index.html and register as new module in Component.js like

jQuery.sap.registerModulePath('SignaturePad', 'SignaturePad');

here SignaturePad is external file.

dilna_tp
Explorer
0 Kudos

hi Rajeesh,

Thank you for your reply.

Could you please elaborate the answer?

Former Member
0 Kudos

you can load external files using script tag in index.html right?

dilna_tp
Explorer
0 Kudos

hi Rajeesh,

I am trying to deploy this app in fiori launchpad,if i mention these js files in index.html it will not load the files in launchpad, so is there any other way to make it work?

Thanks&Regards,

Dilna TP

Former Member
0 Kudos

Hi ,

You can try like this. Hope this helps.


sap.ui.define([

    "sap/ui/core/UIComponent",

    "sap/ui/Device",

 

  "sap/ui/demo/masterdetail/util/Utility"

  

], function(UIComponent, Device, Utility) {

    "use strict";

  

    return UIComponent.extend("sap.ui.demo.masterdetail.Component", {

  

        metadata: {

            manifest: "json",

          

        },

        /**

         * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.

         * @public

         * @override

         */

        init: function() {

            // call the base component's init function

            UIComponent.prototype.init.apply(this, arguments);

            this.setModel(models.createDeviceModel(), "device");

          

        },

      

      

      

    });

  

  

});

Add your js file path inside the sap.ui.define.

Thanks and regards

Indrajith