This article will take you to understand the "module" in angularjs. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Related tutorial recommendations: "angularjs tutorial"
The module defines an application.
Modules are containers for different parts of your application.
Modules are containers for application controllers.
Controllers usually belong to a module.
1 Create a module
You can create a module through the angular.module function of AngularJS:
<div ng-app="myApp">...</div> <script> var app = angular.module("myApp", ['其他模块']); </script>
The "myApp" parameter corresponds to the HTML element that executes the application.
Now you can add controllers, directives, filters, etc. in your AngularJS application.
2 Add a controller
You can use the ng-controller directive to add an application controller:
<div ng-app="myApp" ng-controller="myCtrl"> {{ firstName + " " + lastName }} </div> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; }); </script>
3 Add command
<div ng-app="myApp" runoob-directive></div> <script> var app = angular.module("myApp", []); app.directive("runoobDirective", function() { return { template : "我在指令构造器中创建!" }; }); </script>
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of Understanding 'modules' in Angularjs. For more information, please follow other related articles on the PHP Chinese website!