Created
May 24, 2016 14:07
-
-
Save ielcoro/cd595265f0f8833a21ea226479600703 to your computer and use it in GitHub Desktop.
Angular JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hello = angular.module('hello', []); | |
hello.controller('helloController', ['$rootScope', '$scope', function ($rootScope, $scope) { | |
$scope.isLoggedIn = false; | |
$rootScope.$on('userLogin', function (e) { | |
$scope.isLoggedIn = true; | |
}); | |
$rootScope.$on('userLogout', function (e) { | |
$scope.isLoggedIn = false; | |
}); | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html ng-app="app" lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Angular JS</title> | |
<script src="https://code.angularjs.org/1.5.5/angular.js"></script> | |
<link rel="stylesheet" href="styles.css"> | |
<script src="loginController.js"></script> | |
<script src="helloController.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<div ng-controller="helloController"> | |
<h1 ng-show="isLoggedIn">Welcome! You are logged in!</h1> | |
<h1 ng-show="!isLoggedIn">You are NOT logged in! Please login</h1> | |
</div> | |
<div ng-controller="loginController"> | |
<button ng-show="!loggedIn" ng-click="login()">Login</button> | |
<button ng-show="loggedIn" ng-click="logout()">Logout</button> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var login = angular.module('login', []); | |
login.controller('loginController', ['$rootScope', '$scope', function ($rootScope, $scope) { | |
$scope.loggedIn = false; | |
function login() { | |
console.log('Login!') | |
$scope.loggedIn = true; | |
$rootScope.$broadcast('userLogin'); | |
} | |
function logout() { | |
console.log('Logout!') | |
$scope.loggedIn = false; | |
$rootScope.$broadcast('userLogout'); | |
} | |
$scope.login = login; | |
$scope.logout = logout; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('app', ['hello', 'login']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* todo: add styles */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment