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:

State:

a = angular.module('app.panel', []);
a.config(
function ($stateProvider) {
    $stateProvider
        .state('body.new', {
        url: 'new',
        templateUrl:function($stateParams){
            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.

Answers


rrd February 2016

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

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

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

EDIT:

Or, try this:

a.config(
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

Search




Leave an answer