Science, asked by priyaksrSophia6320, 1 year ago

How can we create controllers and pass parameters in Angular UI route?

Answers

Answered by Samarthattituded
0
Answer }

I need to pass and recieve two parameters to the state I want to transit to using ui-sref of ui-router.

Something like using the link below for transitioning the state to home with foo and bar parameters:

<a ui-sref="home({foo: 'fooVal', bar: 'barVal'})">Go to home state with foo and bar parameters </a>

Receiving foo and bar values in a controller:

app.controller('SomeController', function($scope, $stateParam) { //.. var foo = $stateParam.foo; //getting fooVal var bar = $stateParam.bar; //getting barVal //.. });

I get undefined for $stateParam in the controller.

Could somebody help me understand how to get it done?

Edit}

.state('home', { url: '/', views: { '': { templateUrl: 'home.html', controller: 'MainRootCtrl' }, 'A@home': { templateUrl: 'a.html', controller: 'MainCtrl' }, 'B@home': { templateUrl: 'b.html', controller: 'SomeController' } } });
Similar questions