Hello,
in the component.js init function we do:
var userModel = ..
this.setModel(userModel, "userModel");
How can I get userModelfrom a Modul now? Example:
sap.ui.define([ 'jquery.sap.global', 'ip/Component' ], function(jQuery, Component) {
"use strict";
var UserResource = function() {};
UserResource.prototype.fireGetUserData = function() {
var component = ip.Component;
component.getModel("userModel");
I set a breakpoint and tried that on the console. but component.getModel("userModel"); is undefined. component.getModel is undefined, too.
Getting getManifestEntry() is offered and works with the line:
var url = component.getMetadata().getManifestEntry('sap.ui5').config.resturls.user;
Mostly I read examples, where people add a model to core:
sap.ui.getCore().setModel(..)
and get it from there. But adding it to a component has the benefit, that I can direct use it in n views without getting it in the view-controller first. But what if I want to access it in a controller or in this case a javascript modul?
Regards,
Matthias