angularjs - Angular state : pass multiple parameter without changing url querystring to controller -


i want send parameter app.run logincontroller. because, call state.go() $rootscope.$on() defined inside app.run.

app.run('$rootscope', '$state', '$stateparams',function($rootscope, $state, $stateparams(){     $rootscope.$state = $state;     $rootscope.$stateparams = $stateparams;     $rootscope.$on('unauthorized_access', function (event, args) {         $state.go("page.login", {'error': args.error,'msg': args.msg});     }); }]); 

i have

app.config(['$stateprovider','$urlrouterprovider',function($stateprovider, $urlrouterprovider, $httpprovider){     $urlrouterprovider.otherwise('/');     $stateprovider     // parts omitted...     .state('page.login', {         url: '/login',         views: {             'page': {                templateurl: 'app/landingpage/login.html',                 controller:  'logincontroller',                 params: {obj : {error : null, message: null} }            }         }     }); }]); 

and want pass parameters logincontroller app.run, through $state.go() during transition.

    $state.go("page.login", {'error': err,'message': msg}); 

and in controller, how trying receive params...

app.controller('logincontroller',['$scope', '$state', '$stateparams',   function($scope, $state, $stateparams){     console.log($stateparams.obj); }]); 

i not want change url >> url: '/login/:params' etc. in stateprovider

i referenced page : stackoverflow example

but,was not helpful. appreciated. apologies poor communication.

after long research, ended weird solution. still doubt, whether solution. however, work me.... made hack of ui.router lol ....

i using angular ui-router version v0.2.18. , there @ line no. 3160, have put line of code :

// store hash param later (since stripped out various methods) var hash = toparams['#']; 

and in line no. 3223 have

 if (shouldskipreload(to, toparams, from, fromparams, locals, options)) {     if (hash) toparams['#'] = hash; 

so, thought of passing object '#' key this

.state('page.login', {     url: '/login',     views: {         'body@page': {             templateurl: 'app/landingpage/login.html',             controller:  'logincontroller',             params: {'#' : null},         }     },     authenticate: false }); 

and

$rootscope.$on('unauthorized_access', function (event, args) {     $state.go("page.login", {'#' : {'error': args.error,'msg': args.msg}}); }); 

and surprise, worked..... got object logged in console : console.log($stateparams['#']);

i know solution cunning[udayip in malayalam]... worked me... not mark answer. so, request angular experts provide real solution. if experts say, can solution, mark answer.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -