I want to pass the date value which the user selects in one page to another page using angular UI
routing. There is no parent child relationship between these controllers.Thanks in advance

- 37,412
- 45
- 153
- 234

- 49
- 1
- 2
- 8
-
1Try to observe the concept of Services in Angular. They are singletons, dedicated to that... – Radim Köhler Aug 17 '15 at 09:57
-
ya the services are helpful. But I want the user to pick a date from date picker and that has to be passed across other pages of the application. Is it possible using services? – Heerapreethi P Aug 17 '15 at 11:13
-
Did you found the solution from my answer? if not, then call to my number – Ramesh Rajendran Aug 17 '15 at 11:34
2 Answers
Best Practice
You should create a service with setters and getters for the data that you want to share, you can then instantiate these services in the controllers you wish to share data between.
This lets you safely move data between the two.
Alternative
If you want a quick and dirty way too share data between controllers then use $rootScope, it acts as a global variable but remember that there are problems with these variables see here
Variables set at the root-scope are available to the controller scope via prototypical inheritance.
Every application has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide an event emission/broadcast and subscription facility
Sample
angular.module('myApp', [])
.controller('myCtrl', function($scope, $rootScope) {
$rootScope.myCtrlVariable = new Date();// Your date-picker selected Date
})
.controller('myCtrl2', function($scope, $rootScope) {
$scope.myCtrl2Variable = $rootScope.myCtrlVariable;
});

- 37,412
- 45
- 153
- 234