1

I generate a lot of data in my controller products

I have a link like the following on the products page

<td><a href="/#/getProducts/{{name}}/status" {{ ProductName }}</a></td>

my data is calculated in the products controller

$scope.data = myData

Now instead of re-calculating everything from scratch on the status page and status controller I want to pass myData to the status controller

I also don't want to show the data in the URL

I'm not able to do so. any hints/resources are appreciated

2 Answers 2

1

If you want to share same mydata of one controller onto another, then I would store that as part of service like currentObject.

So each time the user visits the controller that object will be overriden by new myData object.

In the other controller, I would just refer that object. This will make it easier without appending the data as part of the URL params.

Example:

In your service,

app.factory("ProductsService", function() {
   var service = {};
   // your properties for fetching etc
   var _myData;
   service.setMyData = function(myData) {
      _myData = myData;
   }

   service.getMyData = function() {
      return _myData;
   }
   return service;
});

In your one controller, before navigating set that object using ProductService.setMyData(mydata) and in another controller get it using ProductService.getMyData()

Sign up to request clarification or add additional context in comments.

Comments

0

use localstorage to set and get mydata value in different controller

window.localStorage.set("myData", JSON.stringify(myData));

var myData = JSON.parse(window.localStorage.get("myData"));

1 Comment

I get undefined whenever I use localStorage ... must not supported maybe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.