angular js module 的理解

module其实就是一个容器,里面可以装controller,service,directive,filter等,

官网的解释是:Module :A container for the different parts of an app including controllers,services,filters,and directives which configures the injector.

下面的例子中定义了两个angular.module,其中第二个module,依赖第一个module,引用第一个module中的filter方法:

例子的代码如下:

<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="../materialDesignfile/angular.js"></script>
<script>
angular.module("myApp",[])
.filter("greeting",function () {
var ouyangfeng=function (name) {
debugger
return "Hello "+name;
}
return ouyangfeng;
});
angular.module("myApp2",['myApp']).controller("myCtrl",['greetingFilter','$scope',function (greetingFilter,$scope) {
$scope.name=greetingFilter("欧阳凤");
}]);
</script>
<div ng-app="myApp2" ng-controller="myCtrl">
<h1>{{name}}</h1>
</div>
</body>
</html>