0

I want to separate out the logic of my app which needs to call an OData service before the main execution can continue. I have other apps which need this behaviour implemented in the future, so if I can modularise that functionality into a component, it would be very useful.

I have Component.js for the main app, and I'd like to add a second component to be run first, which then loads the main component once the OData result has been received.

How do I load a Component, then get that Component to run the next one (in this case a UIComponent)?

It seems the sap.ui.component code automatically appends "Component.js' to the end of the name provided, so how do you have different Component files with different names?

var oComponent = sap.ui.component({
      name: "MYAPP.Component2",
      id: "componentId"
    });

Returns error, failed to load 'MYAPP/Component2/Component.js' from ./Component2/Component.js: 404 - NOT FOUND

Could anyone provide some example code of a UIComponent having a dependency of a Component, and the file structure of that part of the application?

MKHC
  • 461
  • 4
  • 23
  • Possible duplicate of [Component reuse in manifest.json file](https://stackoverflow.com/questions/46343788/component-reuse-in-manifest-json-file) – Boghyon Hoffmann Nov 12 '17 at 12:47

1 Answers1

1

You can build multiple components as separate entities and then have them listed as dependent components inside a master component for your project. In your main or master component you can list these secondary components under the metadata config's dependencies array. Each component is atomic to itself so each will have its own Component.js with routes and view path. We create nested components in this same manner and it works really well.

KevinS
  • 11
  • 2
  • Thanks for your answer. Could you elaborate on the file structure of an application using multiple components? I have the dependencies section of my metadata defined, but I don't know how to get the second component to run. I have a simple console.log("test") in the init() function of the second component to test it. – MKHC Apr 10 '15 at 14:52