Skip to Content
author's profile photo Former Member
Former Member

this.getRouter() is not a function

Hi,

i'm following an openSap tutorial and in the following code snippet i get the error: "AddFlexibilityRequest.controller.js:8 Uncaught (in promise) TypeError: this.getRouter is not a function".

sap.ui.define(["sap/ui/core/mvc/Controller" ], function(Controller) {
    "use strict";

    return Controller.extend("e4u.usr.a627603.FlexiForecast.WebContent.controller.AddFlexibilityRequest", {

        onInit: function() {
            this.getRouter().getRoute("addFlexibilityRequest").attachPatternMatched(this._onRouteMatched, this);
        },
        
        _onRouteMatched : function() {
            var oModel = this.getModel(this);
            oModel.metaDataLoaded().then(this._onMetaDataLoaded.bind(this));
        },

[...]


 
 
})

I know i can handle this by typing:

sap.ui.core.UIComponent.getRouterFor(this);

But why does this error occur?

Thanks,

Tobias

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 19, 2016 at 03:55 PM

    Probably the tutorial uses a base controller (as e.g. most of the WebIDE templates create) which implements a method "getRouter" containing the logic you described in the second paragraph of your post. The base controller inherits that method to specific controllers. As your controller is used on the sap.ui.core.mvc.Controller you do not have this method.

    Regards,

    Florian

    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.