cancel
Showing results for 
Search instead for 
Did you mean: 

How to call controller functions from index.html in sapui5.

former_member197578
Participant
0 Kudos

Hello experts,

I have created a menubar inside index.html (so that menu can be shown on every page or view). Now i want to navigate to another view after clikcing on menu Item. How do i do that? I am using routing also whose code is written inside component.js.

for eg:

Following is a function written inside some view's controller, when this function is called i navigate to orders view and address also changes. The same function how can be called from index? or any function for that matter?

onInit: function() {

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

  }, // init function of view

handleOrder:function(evt) {

  this.router.navTo("orders");

  }, //called function

Regards,

Chetna

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

fire event in index.html and subscribe in that controller

former_member197578
Participant
0 Kudos

Hello maksim,

I do not understand subscribe in that controller.

Do i need to get that controller inside function? like sap.ui.getCore().byId("view's Id").getController ??

Please explain.

Thank you,

Chetna

former_member197578
Participant
0 Kudos

Hie maksim,

I tried following thing:

var MenuItm1 = new sap.ui.commons.MenuItem({text:"Place Order",

  select :function(oEvent) {

   sap.ui.controller("demo.orders").handleStock();

   },

  });

orders.view:

onInit: function() {

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

handleStock: function(evt) {

  alert("in handle stock");

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

  this.router.navTo("StockStatus");

  },

Though function gets called, but page does not navigate to another view and gives following error:

Cannot read property "navTo" of undefined.

Is there any way in which i can achieve navigation as well as routing in index.html

Regards,

Chetna

former_member182372
Active Contributor
0 Kudos

view instantiate controller not vice versa.

i am not sure i correctly understand what you are trying to do

Former Member
0 Kudos

Will this help.


var MenuItm1 = new sap.ui.commons.MenuItem({text:"Place Order",

  select :function(oEvent) {

   sap.ui.controller("demo.orders").handleStock();

   },

  });


orders.view:

onInit: function() {

that = this;

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

handleStock: function(evt) {

  alert("in handle stock");

that.router.navTo("StockStatus");

  },