Not able to send data using $state.go

679 views Asked by At

I have this code in my angular app. So as the code says, there are multiple views being loaded and I want to pass one parameter.

.state('root.moduleListing', {
    params: ['registerData'],
    views: {
        "main_container": {
            controller: 'ModuleListingController as model',
            templateUrl: 'misc/module-listing/module-listing.tpl.html',
            resolve: {
                registerData: ['$stateParams', function($stateParams) {
                    return $stateParams.registerData;
                }]
            }
        },
        "components_header_header": {
            controller: 'HeaderController as model',
            templateUrl: 'components/header/post-login.tpl.html',
        },
        "components_footer_footer": {
            controller: 'FooterController as model',
            templateUrl: 'components/footer/footer.tpl.html',
        }
    }
}

& I am calling it using

$state.go('root.moduleListing', {'registerdata': response});

& in controller, I am just trying to log it to the console.

module.controller('ModuleListingController', function ($scope, $state, registerData) {
    var model = this;
    console.log("registerData : " + registerData);
}

Now the app doesn't even start i.e. I get an error in the console saying:

failed to instantiate module amcatUI due to:
TypeError: id.match is not a function
    at getArrayMode
1

There are 1 answers

4
Nikhil Aggarwal On BEST ANSWER

Type of defined parameters and toParamas of $state.go should be same array or object on both sides of state transition. Just add your parameters with a default value on your state definition.

You need to update your code from

params: ['registerData'],

to

params: {'registerData' : null},

You can refer to "https://stackoverflow.com/a/26204095/1132354" for detailed answer.

Edit

Also, you will need to update

$state.go('root.moduleListing', {'registerdata': response});

to

$state.go('root.moduleListing', {'registerData': response});

There is a small typo error.