I have this:
%pre%I wanted my second controller to get the $ scope.getIdJobs variable and save it to a variable again. How can I do this?
%pre%app.js
%pre%I have this:
%pre%I wanted my second controller to get the $ scope.getIdJobs variable and save it to a variable again. How can I do this?
%pre%app.js
%pre%A simple solution is to have a factory that returns the value that you need (an object for example): JS:
%pre%HTML:
%pre%Demo: link
When applications get larger, more complex, and harder to test, you may not want to expose the entire object of a factory in this way, but instead give limited access for example via getters and setters:
%pre%With this approach controllers consume the service with new values and use $ watch to observe the changes:
%pre%HTML:
%pre%Demo: link
I'm a beginner too but I'll try to help you by giving two tips:
There is %code% that holds information and when loaded can be passed from controllers to controllers, much used for IDs.
Another way would be to store this %code% in a service and then use it in other controllers by calling it: %code%
You can put the products variable in $ rootScope, so you can access it for $ rootScope anywhere. But I advise you to use the ui-router to make the parameters pass, it gets more cohesive and with less chances of you having undesirable variable value substitution problems, or something like that.
You should set the parameter in your state:
%pre%And it will pass it this way:
%pre%Good,
In my opinion it is advisable to create a %code% for the date, which will be %code% , where you can encapsulate the date and its %code% . Then just call the %code% you need in the controllers.
Here's the example in this jsfiddle
%pre%In the controller that accesses %code% you call the %code% method.
%pre%In the second controller, just declare %code% or if necessary you can filter again with a new id.
%pre%In this way, you can clear the %code% , and everything relative to that date can be reached in %code% and %code% easily.
Or you will have the option of %code% , which also works for what you want.
About routers, I advise you to take a look at ui-router , a far superior tool in my understanding.