Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 2129

How can I access a model set to the component?

$
0
0

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


Viewing all articles
Browse latest Browse all 2129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>