源代码 :
点击运行
<!DOCTYPE html> <html> <body> <div ng-app="" ng-controller="personController"> 名: <input type="text" ng-model="person.firstName"><br> 姓: <input type="text" ng-model="person.lastName"><br> <br> 姓名: {{fullName()}} </div> <script> function personController($scope) { $scope.person = { firstName: "John", lastName: "Doe", }; $scope.fullName = function() { var x = $scope.person; return x.firstName + " " + x.lastName; } } </script> <script src="/try/angularjs/1.2.5/angular.min.js"></script> </body> </html>
运行结果