Created
March 31, 2014 16:35
-
-
Save mrosati84/9896385 to your computer and use it in GitHub Desktop.
This file contains hidden or 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="myApp"> | |
<head> | |
<title></title> | |
</head> | |
<body ng-controller="MainCtrl"> | |
{{ menu }} | |
<div> | |
<button ng-click="setServiceState()">Click</button> | |
</div> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> | |
<script type="text/javascript"> | |
angular.module("myApp", []) | |
.service("Menu", function () { | |
var state = { | |
home: {selected: false}, | |
about: {selected: true} | |
}; | |
return { | |
getState: function () { | |
return state; | |
}, | |
setState: function () { | |
state.home.selected = true; | |
state.about.selected = false; | |
} | |
}; | |
}) | |
.controller("MainCtrl", function ($scope, Menu) { | |
$scope.menu = Menu.getState(); | |
$scope.setServiceState = function () { | |
Menu.setState(); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment