返回到:AngularJS 实例列表
使用 控制器函数,看下这个实例,代码:
<!DOCTYPE html> <html> <title>AngularJS 实例 | Web176教程网web176.com</title> <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="//www.runoob.com/try/angularjs/1.2.5/angular.min.js"></script> </body> </html>
试试吧!
作者:terry,如若转载,请注明出处:https://www.web176.com/angularjsex/6645.html