1
I have a system with Angular and Java.
On the initial route I read the url parameters (some user information such as code, etc.) and saved in $rootScope to access throughout the application.
If I access directly through the browser, works accordingly, the example of the link accessed is this:
http://localhost:3000/#! /login? parametro1=10¶metro2=20
But I have another system that generates these links and sends them by e-mail to some recipients, and they access from the email, with these parameters embedded in the url.
In such cases, Angular loads the main link, but it cleans all the parameters, leaving the url only:
http://localhost:3000/#! /login
To read the parameters, I am using $Location.search() with Angular.
Edit:
I recover the parameters in the "module.run()" of the application’s Angular.
function run($rootScope, $location) {
var data = $location.search();
if (data) {
$rootScope.parametro1= data.parametro1;
$rootScope.parametro2= data.parametro2;
}
}
Angular routes
function config($stateProvider, $urlRouterProvider) {
//Route Default
$urlRouterProvider.otherwise('/login');
//Routes
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'AuthenticationCtrl',
controllerAs: 'vm'
})
}
Login Controller
function AuthenticationCtrl($state, $rootScope, $location) {
var vm = this;
vm.init = init;
init();
function init() {
//Faço o parse, pois esse parâmetro é sempre inteiro..
vm.parametro1 = parseInt($rootScope.parametro1);
}
}
Does anyone know why this behavior?
How to fix this?
Could show the code snippet where you prepare the routes, Geferson?
– OnoSendai
Of course @Onosendai, I already update the post.
– Geferson