javascript - How can I access different $scope in angularJS -
i'm trying manipulate ng-switch in navigation using homectrl route template login button. can't figure out how can access different $scope cleaner way without using rootscope or parent hack. please help.
<body ng-app="myapp"> <div class="nav" data-ng-controller="homectrl"> <div ng-switch on="loggedin"> <p ng-switch-when="false">please login</p> <p ng-switch-when="true">welcome</p> </div> </div> <div class="container" ng-view=""> <!-- partial html --> <button type="button" ng-click="login()">login</button> <button type="button" ng-click="logout()">logout</button> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script> angular.module('myapp', []); angular.module('myapp').controller('homectrl', ['$scope', function($scope) { $scope.loggedin = false; $scope.login = function() { $scope.loggedin = true; }; $scope.logout = function() { $scope.loggedin = false; }; }]); </script> </body>
try 1
<body ng-app="myapp" data-ng-controller="homectrl"> instead of placing inside div
Comments
Post a Comment