RodolfoTVA
RodolfoTVA

Reputation: 77

Trigger a ng-switch inside the controller AngularJs

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

Answers (1)

georgeawg
georgeawg

Reputation: 48968

Set value to "login".

The DEMO

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

Related Questions