2

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
chiwangc
  • 3,566
  • 16
  • 26
  • 32
Ayush
  • 311
  • 1
  • 10

1 Answers1

5

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.

Community
  • 1
  • 1
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59
  • But in that case registerData in the controller will always be null. I want it to be the value being passed in $state.go – Ayush Jun 11 '15 at 09:02
  • It will be the value you pass. null is just the default value. When you say $state.go('root.moduleListing', {'registerdata': response}); then in controller you will have response as registerData. Try it – Nikhil Aggarwal Jun 11 '15 at 09:04
  • There is a typo error as well. $state.go('root.moduleListing', {'registerdata': response}); d in Data should be in capitals. – Nikhil Aggarwal Jun 11 '15 at 09:06
  • 1
    Found no info about the object syntax (as opposed to the array syntax), this is really tricky. Spent a couple hours trying to figure this out until I googled the `id.match` error. Thanks for the help! – Chubas Aug 03 '15 at 20:24