Last active
December 31, 2015 14:22
-
-
Save chenbojian/04dbe5200ae7f44f0cd4 to your computer and use it in GitHub Desktop.
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
angular.module('cbj', []) | |
.provider('singletonProvider', function() { | |
console.log('provider created'); | |
this.$get = function () { | |
console.log('provider $get called'); | |
return {provider: 1}; | |
}; | |
}) | |
.factory('singletonFactory', function() { | |
console.log('factory created'); | |
return {factory: 1}; | |
}) | |
.service('singletonService', function() { | |
console.log('service created'); | |
this.service = 1; | |
}) | |
.constant('singletonConstant', (function () { | |
console.log('constant created'); | |
return {constant: 1}; | |
})()) | |
.value('singletonValue', (function () { | |
console.log('value created'); | |
return {value: 1}; | |
})()); | |
var inj = angular.injector(['cbj']); | |
console.log(inj.get('singletonProvider')); | |
inj.get('singletonProvider').pro = 3; | |
console.log(inj.get('singletonProvider')); | |
console.log(inj.get('singletonFactory')); | |
inj.get('singletonFactory').pro = 3; | |
console.log(inj.get('singletonFactory')); | |
console.log(inj.get('singletonService')); | |
inj.get('singletonService').pro = 3; | |
console.log(inj.get('singletonService')); | |
console.log(inj.get('singletonValue')); | |
inj.get('singletonValue').pro = 3; | |
console.log(inj.get('singletonValue')); | |
console.log(inj.get('singletonConstant')); | |
inj.get('singletonConstant').pro = 3; | |
console.log(inj.get('singletonConstant')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment