在这里,我们已经声明采用ng-controller指令的控制器studentController。作为下一步,我们将定义studentController如下
现在可以使用ng-model或使用表达式如下使用studentController学生的属性。
例子
下面的例子将展示使用控制器。
testAngularJS.html 文件内容如下:
Angular JS Controller AngularJS Sample Application
Enter first name:Enter last name:
You are entering: {{student.fullName()}} function studentController($scope) { $scope.student = { firstName: "Mahesh", lastName: "Parashar", fullName: function() { var studentObject; studentObject = $scope.student; return studentObject.firstName + " " + studentObject.lastName; } }; } script>
输出
在Web浏览器打开textAngularJS.html,看到以下结果: