最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using external js libraries in sapui5 - Stack Overflow

programmeradmin2浏览0评论

So I'm trying to inlcude an external .js file in my SAPUI5 Controller.

    jQuery.sap.includeScript("externalLibrary.min.js", 
    function() {
        //initalizing objects from library
    });

However, the callback which should be called once the script is loaded, never gets called. The error message it gives me is:

"externalLibrary.min.js:16 Uncaught TypeError: Cannot read property 'Constructor' of undefined"

Whats another way I could do this? I was looking into jQuery.sap.registerModulePath() and jQuery.sap.registerResourcePath() but couldn't find a good example of the use of these nor an explaination of the difference between the two online.

Thanks a lot!

So I'm trying to inlcude an external .js file in my SAPUI5 Controller.

    jQuery.sap.includeScript("externalLibrary.min.js", 
    function() {
        //initalizing objects from library
    });

However, the callback which should be called once the script is loaded, never gets called. The error message it gives me is:

"externalLibrary.min.js:16 Uncaught TypeError: Cannot read property 'Constructor' of undefined"

Whats another way I could do this? I was looking into jQuery.sap.registerModulePath() and jQuery.sap.registerResourcePath() but couldn't find a good example of the use of these nor an explaination of the difference between the two online.

Thanks a lot!

Share Improve this question asked Apr 14, 2016 at 11:43 fold4wrap5fold4wrap5 2052 gold badges3 silver badges12 bronze badges 1
  • Which library are you trying to include...maybe that library references another library or dependecy. – Hackerman Commented Apr 14, 2016 at 11:44
Add a ment  | 

3 Answers 3

Reset to default 4

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

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

in fiori launchpad based app , we use ponent.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....",
    id: "IncludeGoogleMapsScript"
}).then(function() { ... })

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

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

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.

发布评论

评论列表(0)

  1. 暂无评论