Angular__Module
AngularJS.module方法返回一个Module对象。Module对象定义的方法返回的结果仍然是Module对象,因此我们可以使用连缀写法。
name //返回模块名称
animation(name,factory)
config(callback) //注册一个在模块加载时进行配置的函数
angular.module("exampleApp.Service",[])
.service("days",function(nowValue){
this.today = nowValue.getDay();
this.tomorrow = this.today + 1;
})
.config(function(){
console.log("Service module config: " + "(no time)");
})
.run(function(startTime){
console.log("Service module run: " + startTime);
});
config方法接收一个函数,该函数在调用方法的模块被加载后调用,常通过注入来自其它服务的值的方式用于配置模块。 run(callback) //注册一个在AngularJS加载完毕后,对所有模块进行配置的函数
run方法的函数在==所有模块==加载完成后以及解析完它们的依赖后才会被调用。 constant(key,value) //定义一个返回常量的服务
myApp.constant("startTime",new Date().getTime());
value(name,value)
var now = new Date();
myApp.value("nowValue",now);
filter(name,factory)
angular.module("exampleApp.Filters",[]).filter("dayName",function(){
return function(input){
return XXX;
}
})
filter用来格式化展示给用户的数据,一旦定义过滤器后,就可以在整个模块中应用。 在视图中使用过滤器,在数据绑定或者表达式后紧跟一个竖线(“|”)以及过滤器的名称。
directive(name,factory)
angular.module("exampleApp",[])
.directive("highlight",function($filter){
var dayFilter = $filter("dayName");
return {
restrict: "AE",link: function(scope,element,attrs){
if(dayFilter(scope.day) == attrs["highlight"]){
element.css("color","red");
}
}
}
});
注意是==scope==,而不是$scope. scope用于检查在试图中可用的数据,attrs参数提供了指令所应用到的元素的属性的完整集合,包括让指令起作用的那个属性。element是一个jqLite对象。 controller(name,constructor)
var myApp = angular.module("myApp",[]);
myApp.controller("myCtrl",function($scope){
});
控制器的命名习惯是使用Ctrl后缀。 provider(name,constructor) //定义一个服务
service(name,constructor) angular.module("exampleApp.Service",[]) .service("days",function(nowValue){ this.today = nowValue.getDay(); this.tomorrow = this.today + 1; })
factory(name,provider) //定义一个服务
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |