1.angularjs的内置服务多,例如:$scope,$rootScope,$http,$q,$resource,$routeProvider等等。
2.Controller 干的事情仅仅就是把相应的数据或者方法绑定到 ViewModel 中。
随着 Angular 1.2 中 Controller As 语法的到来,就不再需要 $scope 了。
this.currentItem = itemService.current();
this.items = itemService.all();
this.add = function(item) {
itemService.add(item);
};
}]);
把不变性的内容(比如基本上所有的方法)作为原型的属性而非对象的属性:
// Angular 1.x with 'controller as' in ES5
myApp.controller('myController', ['itemService', ItemController]);
function ItemController(itemService) {
this.currentItem = itemService.current();
this.items = itemService.all();
}
ItemController.protoype.add = function(item) {
itemService.add(item);
};
4. Provider、Factory、Service、Value、Constant
The Provider(不是泛指)的话具有可配置性,可以在程序运行前进行相应的设定;
Factory 和 Service 除了写法上没有什么区别,喜欢用什么用什么,不一定要按它的名字来;
Value 和 Constant 为单个对象依赖,Constant 可以在 Provider 的配置阶段使用,其他都不能。
作者:Trotyl Yu
链接:http://www.zhihu.com/question/27836513/answer/76686560
2.Controller 干的事情仅仅就是把相应的数据或者方法绑定到 ViewModel 中。
随着 Angular 1.2 中 Controller As 语法的到来,就不再需要 $scope 了。
比如:
// Angular 1.x with 'controller as' in ES5
myApp.controller('myController', ['itemService', function(itemService) {this.currentItem = itemService.current();
this.items = itemService.all();
this.add = function(item) {
itemService.add(item);
};
}]);
把不变性的内容(比如基本上所有的方法)作为原型的属性而非对象的属性:
// Angular 1.x with 'controller as' in ES5
myApp.controller('myController', ['itemService', ItemController]);
function ItemController(itemService) {
this.currentItem = itemService.current();
this.items = itemService.all();
}
ItemController.protoype.add = function(item) {
itemService.add(item);
};
4. Provider、Factory、Service、Value、Constant
The Provider(不是泛指)的话具有可配置性,可以在程序运行前进行相应的设定;
Factory 和 Service 除了写法上没有什么区别,喜欢用什么用什么,不一定要按它的名字来;
Value 和 Constant 为单个对象依赖,Constant 可以在 Provider 的配置阶段使用,其他都不能。
作者:Trotyl Yu
链接:http://www.zhihu.com/question/27836513/answer/76686560