Angular: Empty Fiddle
http://angularjs.org/
by John Harley
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="myApp">
<div ng-controller="MyCtrl">Hello, {{name}}!</div>
<div ng-controller="MyOtherCtrl">Hello, {{name}}!</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.factory('UserService', function () {
return {
name: 'anonymous'
};
});
myApp.provider('UserProvider', function () {
this.$get = function() {
this.name = 'Babe';
return this.name;
};
return "junk";
});
function MyCtrl($scope, UserService) {
UserService.name = 'fred';
$scope.name = UserService.name;
};
function MyOtherCtrl($scope, UserService) {
$scope.name = UserService.name;
};
function MyPCtrl($scope, UserProvider) {
$scope.name = UserProvider;
};
function MyPOtherCtrl($scope, UserProvider) {
$scope.name = UserProvider;
};