Skip to Content

My scenario is i want to show entered input value in view1 to the input box of view2 ?

i scenario is i want to show the input value of the View1 in to the View2?

- i have created the json model in the view and stored the input value in to the json model and assigned that json model in to thhe global var.

- in view2 i used that global var.

- But in view2 input box the value is not shoowing i did binding also.

View1 Code:

View1.Controller.js

View2.XMl

View2.controlle.js

v1.png (11.3 kB)
v2.png (9.0 kB)
v1.png (11.3 kB)
v2.png (9.0 kB)
1.png (41.5 kB)
2.png (52.7 kB)
3.png (39.6 kB)
4.png (45.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 01, 2017 at 11:08 AM

    hi i tried i got for only one time by placing it in the on init function below code.

    now another issue is how to make these code should be called every time before loading the view and how to clear the input field while exiting view2. i tried with the other events also like onbeforerendering and after since they load only one time it not possible to use.

    var temp = g_model ;
     var oInput = this.getView().byId("InP02");
     var temp2 = temp.getData().myValue;
     oInput.setValue(temp2);
    Add comment
    10|10000 characters needed characters exceeded

    • hi i tried use attachPatternMatched and onRouteMatched but it gave error in my program.So i have creted a one More Button as REFRESH and i placed those code in that button press event it worked fine.

      Refresh: function(Eevent) {
      var temp = g_model;
      var oInput = this.getView().byId("InP02");
      var temp2 = temp.getData().myValue;
      oInput.setValue(temp2);
      // console.log(temp.getData().myValue);
      },
  • Feb 28, 2017 at 05:37 PM

    When you want to access data across two views or more then you should have a common area/memory/model/variable to share the data across all the views.

    In your case g_model is set in view1, imagine g_model as a variable.....can you access a variable defined in one file into another file....that is not possible.

    Now the next question is where to define model(g_model)? ....we need to identify the root of "view1" and "view2", this root will most probably "Component.js" or "index.html". If you place the model in this root then it can be accessed in all the views.

    Add comment
    10|10000 characters needed characters exceeded

    • HI,

      Thanks for your comments
      but console statement in the view2 controller returns the actual value which i have entered in view1.

      if it is not g_model accessible than the console statement should return empty.

      console.log(temp.getData().myValue);

      5.png (21.3 kB)