ANGULARJS Instruction Summary II

Source: Internet
Author: User

First of all, the modular, all of the previous article is a normal module, is the HTML inside a ng-controller and then JS inside a method with the same name, so binding data, this is not very good, the problem is that too many global variables are not conducive to code management.

Modular approach:

1 Replace a controller with a module, Ng-app first declares a module.

2 js in this write App=angular.module ("MyApp", [])

App.controller ("Mycontr", function ($scope) {

})

All right, the code behind is a modular notation, good habits.

Ng-repeat

<DivNg-app= "MYAPP"> <DivNg-controller= "Mycontr">     <ul>         <Ling-repeat= "x in Names" >{{x.name + ', ' + X.country}}</Li>     </ul> </Div></Div<script>var app=angular.module ("MyApp", []); App.controller ("Mycontr", function ($scope) {$scope. names = [{name: ' Jani ', Country: ' Norway '}, {    Name: ' Hege ', Country: ' Sweden '}, {name: ' Kai ', Country: ' Denmark '}]; })</Script>

Here are some instructions for input

<DivNg-controller= "Firstcontroller">        <inputtype= "text"Ng-value= "text"ng-disabled= "isdisabled"/>        <inputtype= "text"value= "{{text}}"ng-readonly= "isdisabled"/>        <inputtype= "checkbox"value= "{{text}}"ng-checked= "isdisabled"/>    </Div>App.controller ("Firstcontroller", ["$scope", "$interval", Function ($scope, $interval) {var inow=5;        $scope. text=inow+ "S";        $scope. Isdisabled=true;            var timer= $interval (function () {inow--;            $scope. text=inow+ "S";                if (inow===0) {$interval. Cancel (timer);                $scope. text= "can be clicked";            $scope. Isdisabled=false; }},1000)

ANGULARJS Instruction Summary II

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.