?AngularJS 控制器?控制?AngularJS 應(yīng)用程序的數(shù)據(jù)。
?AngularJS 控制器是常規(guī)的?JavaScript 對象。
AngularJS 控制器 語法
AngularJS 應(yīng)用程序被控制器控制。
ng-controller?指令定義了應(yīng)用程序控制器。
控制器是?JavaScript 對象,由標(biāo)準(zhǔn)的 JavaScript?對象的構(gòu)造函數(shù)?創(chuàng)建。
AngularJS 控制器 示例
<!DOCTYPE html> <html> <meta charset="utf-8"> <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="myCtrl"> 名: <input type="text" ng-model="firstName"><br> 姓: <input type="text" ng-model="lastName"><br> <br> 姓名: {{firstName + " " + lastName}} </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; }); </script> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例