cancel
Showing results for 
Search instead for 
Did you mean: 

this.getRouter() is not a function

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor

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

Answers (0)