Home Ask Login Register

Developers Planet

Your answer is one click away!

Mark February 2016

Angular state with parametes

I am trying to navigate to my state with providing some parameters to it. Here is my code:


a = angular.module('app.panel', []);
function ($stateProvider) {
        .state('body.new', {
        url: 'new',
            return 'http://localhost/' + 'new.aspx?panel_id=' +  $stateParams.panel_id
        controller: 'newController'

I am navigating to this state like this:

var url = $state.href('body.new', { parameter: $scope.parameters });
$window.open(url, '_blank');

In the state $stateParams is undefined. If I am doing it in a wrong way what the correct way might be?

Thanks for help.

Update 1. I have modified my code to this:

url: 'new/:panel_id',
params: {
     parameter: null,

But my problem is that I am still getting $stateParams undefined.


rrd February 2016

Just cutting the code down a little bit, it needs altering to this:

function ($stateProvider, $stateParams) {
  $stateProvider ...

It's complaining about $stateParams because you weren't stating it as a dependency.


Or, try this:

function ($stateProvider, $state) {
  $stateProvider ...

Then you could access it via $state.params.id

Post Status

Asked in February 2016
Viewed 1,186 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life