I have an angular app with two controllers, posts and ctrl. I also use ng-if to hide/show a couple of elements.
The Ctrl-controller sets the value $scope.age to true, If I set age=true in the Posts-controller, ng-if-things get triggered, now they won't get triggered until I reload the page. Why not and what should I do about it?
<body ng-controller="Posts">
<div class="age red" ng-if="!(age)">
<form ng-submit="submit()" ng-controller="Ctrl">
<div class="pair">
<label for="yes">Ja, jag har fyllt 20 år</label>
<input name="yes" type="checkbox" required>
</div>
<input type="submit" value="Gå vidare">
</form>
</div>
<div ng-if="age">
<form class="quiz" ng-class="input"> <label class="first">Dofta på glöggen. Hur doftar Blossa 13?</label>
...
</form>
</div>
<section class="{{post.type}}" ng-repeat="post in posts">
...
</section>
</div>
</body>
Javascript
function Posts($scope, $http) {
$http.get('/getposts')
.success(function(data, status, headers, config) {
$scope.posts = data;
})
.error(function(){
console.log('ajax failed');
});
$scope.age = localStorage.getItem('age');
}
function Ctrl($scope) {
$scope.submit = function() {
localStorage.setItem('age', true);
$scope.age = true;
console.log($scope.age);
};
}