Module of ANGULARJS Learning

Source: Internet
Author: User

1. The module defines an application, the module is the container of the different parts of the application, the module is the container of the application controller, and the controller usually belongs to a module

2. Create the module: You can create the module by Angularjs the Angular.module function:

<div ng-app= "MYAPP" >...</div>

<script>

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

</script>

3. Add Controller: You can use the Ng-controller directive to add an app's 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>

4. Add directive: Angularjs provides a lot of built-in instructions that you can use to add functionality to your app;

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

<script>

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

App.directive ("Runoobdirective", function () {

return{

Template: "I created it in the command builder!" "

};

});

</script>

5. Modules and controllers are included in the JS file: typically ANGULARJS applications include modules and controllers in JavaScript files

<! DOCTYPE html>

<script src= "Http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js" ></script>

<body>

<div ng-app= "myApp" ng-controller= "Myctrl" >

{{firstname+ "" +lastname}}

</div>

<script src= "Myapp.js" ></script>//"Myapp.js" contains the application module's definition program

<script src= "Myctrl.js" ></script>//"Myctrl.js" file contains the controller

</body>

6. The function affects the global namespace:

You should avoid using global functions in **javascript because they are easily overwritten by other script files

The **angularjs module avoids the problem by allowing all functions to be scoped to the module;

* * For HTML applications, it is generally recommended that all scripts be placed at the very bottom of the <body> element, which will increase the page load speed, because HTML loading is not subject to script loading;

**angularjs is loaded in the

Module of ANGULARJS Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.