angularjs - Multiple $stateParams causing controller to be called multiple times -


i have stateprovider looks like:

$stateprovider.state('test.example', {         url: '/test?param1&param2',         templateurl: 'test/testparam.html',         controller: 'testparamctrl' }); 

when console log $stateparams in controller, runs twice. happens when i'm switching between tabs on app. problem doesn't occur if refresh app.

it seems if controller "building" stateparams object , instantiating controller each time. therefore, i'm getting angular errors of param2 being undefined during first instantiation. console logs like:

object {param1: "data1", param2: undefined} // first instantiation object {param1: "data1", param2: "data2"} // second instantiation 

when refresh page, however, 1 console log shows up, "correct one" (i.e. param1 , param2 both defined).

thanks in advance!

my guess in 'test/testparam.html' have ng-controller="testparamctrl". remove ng-controller in template or remove controller property in state definition.