Angularjs has several major features, such as:
1 MVC
2 Modular
3 instruction System
4 Bidirectional data binding
Then this article will look at the Angularjs of the module.
First of all, why do you want to achieve modularity:
1 increases the reusability of the module
2 Customize the load sequence by defining the module
3 in unit tests, you don't have to load all the content
Before doing a few examples, the controller's code directly written in the script tag, so that the declared function is global, obviously not a best choice.
Let's look at how to modularize:
<script type= "Text/javascript" >
var myappmodule = angular.module (' myApp ', []);
Myappmodule.filter (' Test ', function () {return
function (name) {return
' Hello, ' +name+ '! ';
};
});
Myappmodule.controller (' Myappctrl ', [' $scope ', function ($scope) {
$scope. name= ' Xingoo ';
}]);
</script>
First, create the module through the global variable angular myappmodule
Angular.module (' myApp ', []);
The first parameter is the application name of the binding app, which identifies the entry point of the angular in the page, similar to the function of the main function.
The second parameter [] identifies the dependent module.
Let's see how to use the module!
Direct binding MyApp to the Ng-app, it's OK.
In script, we create a filter and a controller from the module.
The role of filter is to add string adornments.
The role of the controller is to initialize the variable.
The results of the program's operation are as follows:
The above is the ANGULARJS modular data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!