AngularJS入門例項2——控制器的使用
阿新 • • 發佈:2019-02-16
<!doctype html> <html> <head> <meta charset="utf-8"> <script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> 單價: <input type="text" ng-model="price"><br> 數量: <input type="text" ng-model="count"><br> <br> 控制器屬性計算的總價: ¥{{price*count}}<br> 控制器方法計算的總價: ¥{{totalPrice()}}<br> </div> <script> angular.module("myApp", []).controller('myCtrl', function($scope) { $scope.price = 0.8; $scope.count = 50; $scope.totalPrice=function(){ return $scope.price*$scope.count; } }); </script> </body> </html>