0

What I want to do is when I choose an option from Selection box in page1 the value of that option will be shown in page 2.

Here is some code that I have tried so far:

App.js:

app.controller('mainController', function ($scope) {
    $scope.sizes = [
        { size: "35" },
        { size: "36" },
        { size: "37" },
        { size: "38" },
        { size: "38" },
    ];
});

In page1:

<select ng-model="selectedSize">
    <option ng-repeat="Size in sizes" value="{{Size.size}} "> {{Size.size}}
    </option>
</select>

In page2:

<p>{{selectedSize}}</p>

Note: page1 and page2 have the same controller.

I really need some help. Thanks a lot!

A.A Noman
  • 5,244
  • 9
  • 24
  • 46
Nhi
  • 31
  • 4
  • declare a variable in a service or factory and assign that value to that service and after that print that value on the second page. or you broadcast the data using rootScope. – Anik Islam Abhi Nov 21 '17 at 05:22
  • As the data is serving from a single controller, what ever you wrote above is correct.Then why it is missing? can you tell us what you are doing after selecting size. Thanks. – skdonthi Nov 21 '17 at 07:20
  • After selecting size, I go to page2 to check if the value is shown. The code would be correct if the line

    {{selectedSize}}

    was on page1. Since it is in page2, the value from the selection box option isn't shown.
    – Nhi Nov 21 '17 at 09:17
  • Possible duplicate of [Share data between html pages](https://stackoverflow.com/questions/11609376/share-data-between-html-pages) – Liam Nov 21 '17 at 12:29
  • hi please accept answer if it worked for you – Pranay Rana Nov 23 '17 at 10:05

2 Answers2

0

if you want to pass data from one page to another page , you can make use of

  • QueryString
  • SessionStorage, LocalStorage
  • Cookies
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0

If page1 and page 2 are of same controller

  • Try storing the value in scope variable.

If not in same controller

  • Store it in $rootScope variable and access.

  • If you would like to show the value in page2 URL. Try storing in a id in state url and access it using Stateparams.

  • Else store in localStorage variable and clear it(if you don't want further).