Angularjs has several major features, such as:
1 MVC
2 modularity
3 instruction System
4 Bidirectional data binding
Then this article will take a look at the Angularjs modularity.
First of all, let's talk about why modularity is possible:
1 Increased reusability of modules
2 Customizing the load order by defining the module
3 in unit tests, you do not have to load all the content
In a few examples, the controller's code is written directly inside the script tag, so that the declared function is global and is obviously not the best choice.
Here's a 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 with the global variable angular myappmodule
Angular.module (' myApp ', []);
The first parameter is the binding app name, which identifies the entry point of the angular in the page, similar to the function of main.
The second parameter [] identifies the dependent module.
Let's see how to use the module now!
<!doctype html>
Directly bind MyApp to Ng-app, it is possible.
In script, we created a filter and a controller through the module.
The role of filter is to add string adornments.
The function of the controller is to initialize the variable.
The running results of the program are as follows:
The above is the ANGULARJS modular data collation, follow-up continue to supplement the relevant information, thank you for the support of this site!