Skip to content Skip to sidebar Skip to footer

Using External Js Libraries In Sapui5

So I'm trying to inlcude an external .js file in my SAPUI5 Controller. jQuery.sap.includeScript('externalLibrary.min.js', function() { //initalizing objects from

Solution 1:

You can try jQuery.sap.includeScript(vUrl, sId?, fnLoadCallback?, fnErrorCallback?)

https://sapui5.hana.ondemand.com/docs/api/symbols/jQuery.sap.html#.includeScript

in fiori launchpad based app , we use component.js as root , so we don't have index.html to include scripts (if you use XML view instand of HTML view).

try

jQuery.sap.includeScript({
    url: "https://maps.googleapis.com...",
    id: "IncludeGoogleMapsScript"
}).then(function() { ... })

Not working in portal service , fallback is provided : UsingjQuery.sap.includeScript().then() in HCP Firori Launchpad


Solution 2:

You can use jQuery.sap.registerResourcePath('lib', URL) and then jquery.SAP.require('lib.file'). You can do both one after another or register in the init and later require. Does not matter. I don't have an example at hand as I am on a phone but it works. What you need to keep in mind is that this example would load something like URL/file.js so you need to adjust accordingly. The name you give to the lib does not matter. You can also inject a script tag into the current page ,however, the require will load the external lib synchronously while if you inject a script tag you need to wait until it is loaded with a callback.

PS: the capitalization on those methods is not right


Solution 3:

Got it! For future reference, it works to load the files from the index html like so:

 <script src="library.js"></script>

The main problem was that I was trying to include external dependencies which also contained jQuery. So, I had to remove that from the file and now it's working.


Post a Comment for "Using External Js Libraries In Sapui5"