Skip to content

Instantly share code, notes, and snippets.

@Wcc723
Last active August 30, 2015 08:55
Show Gist options
  • Save Wcc723/43ab94d1d16041b922b7 to your computer and use it in GitHub Desktop.
Save Wcc723/43ab94d1d16041b922b7 to your computer and use it in GitHub Desktop.
Angular
angular.module('app')
.provider('buy', [function () {
// 可以被初始化設定的
var vm = this;
vm.defaults = {};
vm.defaults.counter = 1;
this.$get = [function() {
// 要處理的
// 還可以用遞包技巧
var counter = vm.defaults.counter;
return {
'item': ['factory',1,2,3],
getCounter: function(){
return counter++;
}
};
}];
}])
.factory('by2', [function () {
// 要處理的
// 還可以用遞包技巧
var counter = 0;
return {
'item': ['factory',1,2,3],
getCounter: function(num){
return num + counter++;
}
};
}])
.service('by3', [function () {
// servcie 是被 new 起來的
// 預設值的意思
// 看起來很潮
this.items = ['service', 3,2,5]
}])
.value('by4', {
// 單純回傳值,或是共用值
// 不能傳進 config
items: ['value',1]
})
.constant('by5', {
// 可以注入到任何地方
// 常數
// 基本上沒有做運算
items: ['constant',1]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment