$stateChangeSuccess, always the same value of $state.params
<p>I can't wrap my head around this, I'm really struggling with <code>ui-route</code>and <code>$stateChangeSuccess</code> and <code>$watch</code>, got two issues. I'm trying to change a value of a parameter, when I change the <code>state</code>, click a url. I think it's important to know that I use sub-states. With my current setup I get that the <code>$stateChangeSuccess</code> triggers twice on load, meaning it sets the value right away. What I'm trying to do is to only have it set on change of url.</p>

<p>My route looks like this, I'm trying to set the value of a parameter </p>

<pre><code>.state('medications', {
                url: '/medications',
                templateUrl: '/partials/home.html',
                controller: 'mainController',
                params: { showSection: false },
                resolve: {
                    postPromise: ['medicationservice', function(medicationservice) {
                        return medicationservice.getAll();
                    }]
                }
            })
            .state('medications.add', {
                url: '/add',
                templateUrl: '/partials/home.html',
                controller: 'mainController',
                params: { showSection: true },
            })
</code></pre>

<p>in my controller I got the following, where I set the <code>openSesame</code> parameter to <code>false</code> explicitly on <code>init</code>, but as described it triggers and sets it to <code>true</code>.</p>

<pre><code>mainModule.controller('mainController', [
        '$scope',
        '$state',
        '$rootScope',
        'medicationservice',
        function($scope, $state, $rootScope, medicationservice) {
            $scope.medication = {};
            $scope.medications = medicationservice.posts;
            $scope.openSesame = false;

            $rootScope.$on("$stateChangeSuccess", function() {
                $scope.openSesame = true;
                console.log($scope.openSesame);
            });
}]);
</code></pre>

<p><a href="https://plnkr.co/edit/ZEvKONRoR46k3VLSlth5?p=preview" rel="nofollow">in my plunker</a> the state change works once, that is if I use the <code>$rootScope</code>.</p>