Skip to Content
author's profile photo Former Member
Former Member

How to add external js file in component.js ?


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"sap/ui/demo/masterdetail/util/Utility");"sap/ui/demo/masterdetail/util/JOB");"sap/ui/demo/masterdetail/util/globalvariables");"sap/ui/demo/masterdetail/util/DecodeWorker");"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.

util files.PNG (14.1 kB)
util folder.PNG (5.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Aug 18, 2016 at 09:40 AM

    you can load it in index.html and register as new module in Component.js like'SignaturePad', 'SignaturePad');

    here SignaturePad is external file.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi ,

      You can try like this. Hope this helps.

      ], 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


  • Posted on Aug 18, 2016 at 12:27 PM

    encapsulate the external js as module

    example: JOB.js''nampace.JOB')


    when u want to use it

    1. sap.ui.define([
    2. "sap/ui/core/UIComponent",
    3. "sap/ui/Device",
    4. "namespace/JOB"
    5. ], function(UIComponent, Device, JOB) {
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.