Reputation: 77
I am trying to trigger my ng-switch from the controller, but I have no idea how to do that.
HTML
<div ng-switch="menu">
<div ng-switch-when="login" login-page></div>
<div ng-switch-when="accountmain" accountmain-page></div>
</div>
Controller
if ($scope.loginStatus == '200') {
$scope.menu = value;
}
Nothing happens if I do like that :(
Upvotes: 0
Views: 100
Reputation: 48968
Set value
to "login"
.
angular.module("app",[])
.controller("ctrl", function($scope) {
$scope.loginStatus = '200';
var value = 'login';
if ($scope.loginStatus == '200') {
$scope.menu = value;
}
});
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app="app" ng-controller="ctrl">
<div ng-switch="menu">
<div ng-switch-when="login" login-page>LOGIN PAGE</div>
<div ng-switch-when="accountmain" accountmain-page>ACCOUNT PAGE</div>
</div>
<button ng-click="menu='login'">GOTO Login</button>
<button ng-click="menu='accountmain'">GOTO Account</button>
</body>
For more information, see
Upvotes: 1