angular ui router - How to access state params (ui-sref) without including them in URL propery of state in angularjs -
this question might similar different requirements. not able make comment (required 50 points) replicating question.
i want access parameters sent ui-sref in template inside controller without mentioning them in state url .
something using link below transitioning state home foo , bar parameters:
<a ui-sref="home({foo: 'fooval', bar: 'barval'})">go home state foo , bar parameters </a>
receiving foo , bar values in controller:
state('home', { url: '/:foo', views: { '***whatisthis***': { templateurl: 'home.html', controller: 'mainrootctrl' }, app.controller('somecontroller', function($scope, $stateparam) { //.. var foo = $stateparam.foo; //getting fooval var bar = $stateparam.bar; //getting barval //.. });
i undefined $stateparam in controller.
could me understand how done? want bar without adding url
if of params not supposed show in url, need combine url
, params
:
.state('home', { url: '/:foo', params: { foo: 'default value of foo', bar: 'default value of bar' }, ... })
and use $stateparams
properly:
.controller('somecontroller', ['$scope', '$stateparams', function ($scope, $stateparams) { // ... (use $stateparams) }])
and, if you're still stuck, please take @ working codepen demo.
Comments
Post a Comment