KaronatoR
KaronatoR

Reputation: 2653

Ionic $stateParams undefined

please help me with ionic $stateParams issue.

Here is state configuration

.state('tabs.categories', {
    url: "/categories/:parentID",
    views: {
        'categories-tab': {
            templateUrl: "templates/categories.html",
            controller: 'CategoriesCtrl'
        }
    }
})

Controller:

angular.module('myApp').controller('CategoriesCtrl', ['$scope', '$http', '$stateParams', function($scope, $stateParams, $http){

console.log ($stateParams.parentID);

}]);

And view (if need):

<ion-view view-title="Categories">
<ion-content>

<a class="button button-clear" href="#/tab/categories/2">cat 2</a>
<a class="button button-clear" href="#/tab/categories/3">cat 3</a>

</ion-content>

$stateParams.parentID is undefined in controller, can't understand why. Thanks for your time.

Upvotes: 1

Views: 4107

Answers (1)

Muhammad Reda
Muhammad Reda

Reputation: 27023

The order of your injected services is in correct, change this line

angular.module('myApp').controller('CategoriesCtrl',
    ['$scope', '$http', '$stateParams',
    function($scope, $stateParams, $http){

to be

angular.module('myApp').controller('CategoriesCtrl',
    ['$scope', '$http', '$stateParams',
    function($scope, $http, $stateParams){

Upvotes: 4

Related Questions