StackOverflow_25803988: angularjs-multiple-ng-if-are-not-being-updated-simultaneously-why-how-to-fix

Illustration of answer to http://stackoverflow.com/questions/25803988/angularjs-multiple-ng-if-are-not-being-updated-simultaneously-why-how-to-fix.

by ExpertSystem

HTML

<script src="http://code.angularjs.org/1.2.24/angular.min.js"></script>
<div ng-controller="mainCtrl">
    <div ng-switch="user.facebook">
        <button ng-click="user.facebook=true" ng-switch-default>
            Link Facebook
        </button>
        <button ng-click="user.facebook=false" ng-switch-when="true">
            Unlink Facebook
        </button>
    </div>
    <pre>user: {{user | json}}</pre>
</div>

<!-- -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- -->
<!-- Page Footer -->
<small class="footer" ng-controller="footerCtrl">
    <b>Angular v{{version.full}}</b> ({{version.codeName}})
    <span class="right">
        &copy;
        <a ng-href="{{author.url}}" target="_blank">{{author.name}}</a>
    </span>
</small>

CSS

/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
body { padding-bottom: 22px; }
.footer { background-color: White; border-top: 1px solid rgba(100, 100, 100, 0.33); bottom: 0; display: block; font-size: 0.75em; height: 20px; left: 0; margin: 0 5px; overflow: auto; padding: 5px; position: fixed; right: 0; }
.right { float: right; }

JavaScript

var app = angular.module('myApp', []);
app.controller('mainCtrl', function ($scope) {
    $scope.user = {facebook: false};
});

/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
app.controller('footerCtrl', function ($scope) {
    $scope.version = angular.version;
    $scope.author  = {
        name: 'ExpertSystem',
        url:  '//stackoverflow.com/users/2341938/expertsystem'
    };
});