AngularJS Modules & Forms

Source: Internet
Author: User

The module defines an application.

A module is a container for different parts of an application.

The module is the container for the application controller.

The controller usually belongs to a module.

Application ("MYAPP") with controller ("Myctrl"):

<DivNg-app= "MYAPP"Ng-controller= "Myctrl">{{firstName + "" + LastName}}</Div><Script>varapp=Angular.module ("myApp", []); App.controller ("Myctrl", function($scope) {$scope. FirstName= "John"; $scope. LastName= "Doe";});</Script>

Typically AngularJS applications include modules and controllers in JavaScript files. You should avoid using global functions in JavaScript. Because they are easily overwritten by other script files.

The AngularJS module avoids this problem by allowing the scope of all functions to be changed under the module.

When to load storage

The AngularJS is loaded in the

Another solution is to load the AngularJS library in the <body> element, but it must be placed in front of your AngularJS script:

The AngularJS form is a collection of input controls.

Instance

<DivNg-app= "MYAPP"Ng-controller= "Formctrl">  <formnovalidate>First Name:<BR>    <inputtype= "text"Ng-model= "User.firstname"><BR>Last Name:<BR>    <inputtype= "text"Ng-model= "User.lastname">    <BR><BR>    <ButtonNg-click= "Reset ()">RESET</Button>  </form>  <P>Form = {{User}}</P>  <P>Master = {{Master}}</P></Div><Script>varapp=Angular.module ('myApp', []); App.controller ('Formctrl', function($scope) {$scope. master={firstName:"John", LastName:"Doe"}; $scope. Reset= function() {$scope. User=angular.copy ($scope. master);    }; $scope. Reset ();});</Script>

The ng-app directive defines the AngularJS application.

The ng-controller directive defines the application controller.

The ng-model directive binds two input elements to the model's user object.

The Formctrl function sets the initial value of the Master object and defines the reset () method.

The Reset () method sets the user object equal to the Master object.

The ng-click directive invokes the reset () method and is called when the button is clicked.

AngularJS Modules & Forms

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.