Kurkula Kurkula - 9 days ago 6
AngularJS Question

AngularJs Moving data to redirected page

I am trying to use data in a redirected page which is redirected in angular.
How can I move data in this case. I tried using in rootscope but is this preferable? is ther any way where I can use the data from first page and use it in the page after redirection?

var app = angular.module('urlApp', []);
app.controller('urlCtrl', function ($scope, $log, $window) {
$scope.ClickMeToRedirect = function () {
$scope.myData = datafrommyDb;//This is what I am planning to use in redirected page
var url = "http://" + $window.location.host + "/Account/Login";
$log.log(url);
$window.location.href = url;
};
});

Answer

If you want use data across different controllers, you can use angular service. Since service are singleton object, the same object is getting injected to different controllers. $rootScope is not preferred because it is common to all the controllers and we might not be using the data in all the controllers. check this links

$rootScope vs. service - Angular JS

Share data between AngularJS controllers

Comments