cancel
Showing results for 
Search instead for 
Did you mean: 

when i'm using router, I have Error ("Can't read property 'navTo' of undefined )

Former Member
0 Kudos

I want to move page when i succeed to check login information. However it didn't work

below is my code.

oModel.read("/LOGIN_INFOSet(USRID='"+USRID+"',PASWD='"+PASWD+"')",null,null,false,

function(oData,repsonse){

  oJsonModel.setData(oData);

  sap.ui.core.UIComponent.getRouterFor(this).navTo("Master" ,{

  currentView : this.getView()

  }, true);

  },

  function(oError){

  alert("Invalid Login Info. Please Check User ID and Password")

  }

  );

When i tried navTo code outside of function, it work.. see below

oModel.read("/LOGIN_INFOSet(USRID='"+USRID+"',PASWD='"+PASWD+"')",null,null,false,

  function(oData,repsonse){

  oJsonModel.setData(oData);

  },

  function(oError){

  alert("Invalid Login Info. Please Check User ID and Password")

  }

  );

sap.ui.core.UIComponent.getRouterFor(this).navTo("Master" ,{

  currentView : this.getView()

  }, true);

I want to use navigation code inside of success function. DO you guys have any Idea

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

again "this" issue.

just remember   this inside of the nested function is not the this you want.....

var that=this;

oModel.read("/LOGIN_INFOSet(USRID='"+USRID+"',PASWD='"+PASWD+"')",null,null,false,

function(oData,repsonse){

  oJsonModel.setData(oData);

  sap.ui.core.UIComponent.getRouterFor(that).navTo("Master" ,{

  currentView : this.getView()

  }, true);

  },

  function(oError){

  alert("Invalid Login Info. Please Check User ID and Password")

  }

  );

junwu
Active Contributor
0 Kudos

oModel.read("/LOGIN_INFOSet(USRID='"+USRID+"',PASWD='"+PASWD+"')",null,null,false,

function(oData,repsonse){

  oJsonModel.setData(oData);

  sap.ui.core.UIComponent.getRouterFor(this).navTo("Master" ,{

  currentView : this.getView()

  }, true);

  }.bind(this), //this should also work

  function(oError){

  alert("Invalid Login Info. Please Check User ID and Password")

  }

  );

Answers (1)

Answers (1)

ugurkaya
Active Participant
0 Kudos

Just as an alternative you can use:

jQuery.proxy(function(oData, oResponse){

  oJsonModel.setData(oData);

  sap.ui.core.UIComponent.getRouterFor(this).navTo("Master" ,{

    currentView : this.getView()

  }, true);

},this),