Home > Web Front-end > JS Tutorial > body text

Understanding 'modules' in Angularjs

青灯夜游
Release: 2021-02-01 11:45:44
forward
2137 people have browsed it

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.

Understanding 'modules' in Angularjs

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", [&#39;其他模块&#39;]);

</script>
Copy after login

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>
Copy after login

3 Add command

<div ng-app="myApp" runoob-directive></div>

<script>

    var app = angular.module("myApp", []);

    app.directive("runoobDirective", function() {
        return {
            template : "我在指令构造器中创建!"
        };
    });
</script>
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!