Angular: Empty Fiddle
http://angularjs.org/
by l0co
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
Hello, {{name}}!
</div>
<div ng-controller="MyCtrl2">
Hello, {{name}}!
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.service('myService', function() {
console.log('instantiating service');
this.someFunc = function() {
return 'hello from service';
}
});
function MyCtrl($scope, myService) {
console.log('MyCtrl:service', myService.someFunc());
$scope.name = 'Superhero';
}
function MyCtrl2($scope, myService) {
console.log('MyCtrl2:service', myService.someFunc());
$scope.name = 'World';
}