Created
April 11, 2015 12:17
-
-
Save GrahamWalters/68614da03d19ee97ea0a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hamibiwura
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> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-app="app"> | |
<div ng-controller="Ctrl1"></div> | |
<div ng-controller="Ctrl2"></div> | |
<script id="jsbin-javascript"> | |
console.log('A service wraps a factory.'); | |
console.log('All providers in Angular are singletons.'); | |
var app = angular.module('app', []); | |
app.factory('MatchFactory', function() { | |
var Match = function() { | |
console.log('MatchFactory'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}; | |
Match.prototype.helloP = function() { | |
console.log('HelloP '+this.name); | |
}; | |
return new Match(); | |
}); | |
app.service('MatchService', function() { | |
console.log('MatchService'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}); | |
app.controller('Ctrl1', function(MatchFactory, MatchService) { | |
MatchFactory.setName('Ben'); | |
MatchService.setName('Jerry'); | |
}); | |
app.controller('Ctrl2', function(MatchFactory, MatchService) { | |
MatchFactory.hello(); | |
MatchFactory.helloP(); // prototype functions also work | |
MatchService.hello(); | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-app="app"> | |
<div ng-controller="Ctrl1"></div> | |
<div ng-controller="Ctrl2"></div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.log('A service wraps a factory.'); | |
console.log('All providers in Angular are singletons.'); | |
var app = angular.module('app', []); | |
app.factory('MatchFactory', function() { | |
var Match = function() { | |
console.log('MatchFactory'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}; | |
Match.prototype.helloP = function() { | |
console.log('HelloP '+this.name); | |
}; | |
return new Match(); | |
}); | |
app.service('MatchService', function() { | |
console.log('MatchService'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}); | |
app.controller('Ctrl1', function(MatchFactory, MatchService) { | |
MatchFactory.setName('Ben'); | |
MatchService.setName('Jerry'); | |
}); | |
app.controller('Ctrl2', function(MatchFactory, MatchService) { | |
MatchFactory.hello(); | |
MatchFactory.helloP(); // prototype functions also work | |
MatchService.hello(); | |
});</script></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
console.log('A service wraps a factory.'); | |
console.log('All providers in Angular are singletons.'); | |
var app = angular.module('app', []); | |
app.factory('MatchFactory', function() { | |
var Match = function() { | |
console.log('MatchFactory'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}; | |
Match.prototype.helloP = function() { | |
console.log('HelloP '+this.name); | |
}; | |
return new Match(); | |
}); | |
app.service('MatchService', function() { | |
console.log('MatchService'); | |
this.name = ''; | |
this.setName = function(name) { | |
this.name = name; | |
}; | |
this.hello = function() { | |
console.log('Hello '+this.name); | |
}; | |
}); | |
app.controller('Ctrl1', function(MatchFactory, MatchService) { | |
MatchFactory.setName('Ben'); | |
MatchService.setName('Jerry'); | |
}); | |
app.controller('Ctrl2', function(MatchFactory, MatchService) { | |
MatchFactory.hello(); | |
MatchFactory.helloP(); // prototype functions also work | |
MatchService.hello(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment