Skip to content

Instantly share code, notes, and snippets.

@mrosati84
Created March 31, 2014 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrosati84/9896385 to your computer and use it in GitHub Desktop.
Save mrosati84/9896385 to your computer and use it in GitHub Desktop.
<!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