I am trying to update a value in my nav.html
<nav class="navbar navbar-inverse" role="navigation" ng-controller="LoginController as login">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li><a href="#/foo">Show option '{{login.showOption.show}}' <span class="glyphicon glyphicon-info-sign"></span></a></li>
<li ng-if="login.showOption.show" dropdown>
<a href class="dropdown-toggle" dropdown-toggle>
Options <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a ng-href>1</a></li>
<li><a ng-href>2</a></li>
</ul>
</li>
</ul>
</div>
</nav>
The {{login.showOption.show}}
is referring to this controller
'use strict';
(function (module) {
var LoginController = function (basicauth, currentUser, growl, loginRedirect, Option, $modal, $log) {
var model = this;
model.showOption = Option.value;
};
module.controller("LoginController", ['basicauth', 'currentUser', 'growl', 'loginRedirect', 'Option', '$modal', '$log', LoginController]);
}(angular.module("civApp")));
The Option service
'use strict';
(function (module) {
var option = function () {
var value = {
show: false
};
return {
value: value
};
};
module.service("Option", option);
}(angular.module("civApp")));
When the value of hasAccess changes, I want the nav.html also to either show or not show
'use strict';
(function (module) {
var GameController = function ($log, $routeParams, GameService, PlayerService, currentUser, Util, Option, $filter, ngTableParams, $scope, growl, $modal) {
var model = this;
$scope.$watch(function () {
return GameService.getGameById(model.gameId);
}, function (newVal) {
if (!newVal) {
return;
}
var game = newVal;
$scope.currentGame = game;
var hasAccess = game.player && game.player.username === model.user.username && game.active;
$scope.userHasAccess = hasAccess;
Option.value = {
show: hasAccess
};
//$scope.apply() <-- fails
return game;
});
};
module.controller("GameController",
["$log", "$routeParams", "GameService", "PlayerService", "currentUser", "Util", 'Option', "$filter", "ngTableParams", "$scope", "growl", "$modal", GameController]);
}(angular.module("civApp")));
But the problem is that nothing happens. I think its because I am inside a watch, and I need to either use apply or digest, but I don't know how!
Here is link to the code
The code is here: https://github.com/cash1981/civilization-boardgame/blob/feature/options/civilization-web/app/scripts/controllers/GameController.js
and