How can I update a variable from an AngularJS view?
<h1>What I want</h1>

<p>I have 3 views. All views have their own controller. The first view is home. From the home view the user goes to view 2 by clicking on a div element. On view 2 the user opens view 3 by clicking on a button. On view 3 the user clicks on a button and goes back to view 2.</p>

<p>The problem I am facing is that I want to know if the user came from view 2. In that case I want to show different content then when the user came from the home view.</p>

<h1>Create another view</h1>

<p>Can it be done without creating another view?</p>

<h1>My try</h1>

<p>I created a service that keeps track of if I came from view 3, but the controller of view 2 isn't executed anymore after view 2 got opened from the home view. So basicly <code>$scope.fromViewThree</code> isn't updated and still false.</p>

<p>I added <code>$route.reload()</code> before <code>$window.location = "#/app/viewtwo";</code> because I thought it would reinitialise the controllers(<a href="https://stackoverflow.com/a/26504777/4815184">source</a>) and then <code>$scope.fromViewThree</code> should have been updated. I also tried adding it below <code>$window.location = "#/app/viewtwo";</code>.</p>

<h2>Controller view 2</h2>

<pre class="lang-js prettyprint-override"><code>.controller('ViewTwoCtrl', function($scope, $window, fromViewThree) {
    $scope.fromViewThree = fromViewThree.getBoolean();
    fromViewThree.setBoolean(false);
    $scope.goToViewThree = function() {
        $window.location = "#/app/viewthree";
    };
})
</code></pre>

<h2>Controller view 3</h2>

<pre class="lang-js prettyprint-override"><code>.controller('ViewThreeCtrl', function($scope, $window, fromViewThree) {
    $scope.goToViewTwo = function() {
        fromViewThree.setBoolean(true);
        $window.location = "#/app/viewtwo";
    };
})
</code></pre>

<h2>Directives.js</h2>

<pre class="lang-js prettyprint-override"><code>.service('fromViewThree', function () {
        var b = false;

        return {
            getBoolean: function() {
                return b;
            },
            setBoolean: function(value) {
                b = value;
            }
        };
})
</code></pre>

<h2>HTML view 2</h2>

<pre class="lang-html prettyprint-override"><code>&lt;div ng-if="fromViewThree == false"&gt;
    &lt;p&gt;You came from view home!&lt;/p&gt;
&lt;/div&gt;
&lt;div ng-if="fromViewThree == true"&gt;
    &lt;p&gt;You came from view three!&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;
    &lt;button ng-click="goToViewThree()" ng-if="fromViewThree == false"&gt;Go to view 3&lt;/button&gt;
    &lt;button ng-click="goToViewThree()" ng-if="fromViewThree == true"&gt;Go again to view 3&lt;/button&gt;
&lt;/div&gt;
</code></pre>

<h2>HTML view 3</h2>

<pre class="lang-html prettyprint-override"><code>&lt;div class="row"&gt;
    &lt;button class='button' ng-click="goToViewTwo()"&gt;Lets go to view two!&lt;/button&gt;
&lt;/div&gt;
</code></pre>