AngularJs學習第二章(AngularJs表達式)

AngularJs表達式html

AngularJs表達式寫在雙大括號內:{{expression}}express

AngularJS表達式把數據綁定到HTML,與ng-bind指令有 殊途同歸之妙app

AngularJS將在表達式書寫的位置「輸出」數據spa

AngularJS很像JavaScript表達式:他能夠包含文字、運算符和變量code

實例:cdn

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js">
</script>
</head>
<body>
<div ng-app=""> <p>個人第一個表達式: {{ 5 + 5 }}</p> </div>
</body>
</html>
輸出結果:
  個人第一個表達式: 10
AngularJS應用
  AngularJS模塊( Moudule)用於AnjularJS應用
   ng-app指令定義了應用, ng-controller定義了控制器。
AngularJs實例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>htm

<p>嘗試修改如下表單。</p>ip

<div ng-app="myApp" ng-controller="myCtrl">utf-8

名: <input type="text" ng-model="firstName"><br>
姓: <input type="text" ng-model="lastName"><br>
<br>
姓名: {{firstName + " " + lastName}}input

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
});
</script>

</body>
</html>

AngularJS模塊定義應用:

   AnjularJS模塊

  var app = angular.module('myApp',[]);

AngularJS控制器控制應用:

  AnjularJS控制器:

    app.controller('myCtrl',function($scope){

      $scope.firstName = "John";

      $scope.lastName = "Doe";

  })

相關文章
相關標籤/搜索