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