AngularJS (1)

Source: Internet
Author: User

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)

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.