Skip to Content
-1

Add resource/file/function to project at runtime

Hi Friends,

let say I have this as a string:

sap.ui.define([], function() {
    "use strict";
    return {
        testFunc: function() {
            alert("function");
        }
    };
});

Now I want to call the above function "testFunc()" from my controller, like:

sap.ui.define(["sap/ui/core/mvc/Controller","...pfad.to.function], 
function(Controller, Function) {
    "use strict";
    return Controller.extend("CONT", {
        onInit: function() ;
           Function.testFunc();
        },
    })
});

But I get only at runtime the above string. So I would think. I create a resource(file.js) at runtime, put the string in there and call the function. But I have no idea how to manage this. I tried with sap.ui.define("functionjs") and then functionjs = string above. And I can find the functionjs in the controller, but I can not call the function testFunc().

Is there a way to manage this?

Rg. Joerg

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Feb 15, 2018 at 07:07 PM

    what you are designing?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 15, 2018 at 07:08 PM
    sap.ui.define([],function(){"use strict";return{
            testFunc:function(){
                alert("function");}};});

    if that piece is stored in backend statically. why not just put them in your web app.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 16, 2018 at 12:42 PM

    can you tell a bit background?

    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.