Module
when using Angularjs to write code, we often divide different functions into different modules to write, so as to better division of labor, improve work efficiency.
First//define the main module
Angular.module ("Mainapp", ["Mainapp.contrl", "Mainapp.filter"]);
The first parameter is the main module name, followed by the name of the submodule in parentheses.
Angular.module ("Mainapp.contrl", [])
. Controller ("Maincontrl", function ($scope) {
$scope. ary=[14,24,58,44,51,67];
});
above is a random list of a controller sub-module. If you want to continue adding additional controller modules, simply add them later, as shown in the following code
Angular.module ("Mainapp.contrl", [])
. Controller ("Maincontrl", function ($scope) {
$scope. ary=[14,24,58,44,51,67];
}). controller ("Maincontrl1", function ($scope) {
$scope. ary1=[14,24,58,44,51,67];
});
If you are defining an additional module, you need to create a new module.
Angular.module ("Mainapp.filter", [])
. Filter ("Orderbyfilter", function () {
Alter ("1");
});
These new modules must have their names added to the main module.
instruction
based on our understanding of HTML elements, directives are essentially the way that Angularjs extends HTML elements with custom functionality. We can customize an element by code, it can be used as a normal label, and can work in the browser.
Angular.module ("Mainapp.directive", [])
. directive (' say ', function () {
return {
restrict: "E",
template: "<span>hellow world!</span>",
replace: True
}
&NBSP;&NBSP;&NBSP;&NBSP;})
the code above, customizing a ' say ' element.
AngularJS (1)