AngularJS 控制器未显示结果
AngularJS Controllers not showing the result
当用户在文本框上输入文本时 {{student.fullName()}} 应该更新。但这是行不通的。有帮助吗?
示例应用程序
<div ng-app = "mainApp" ng-controller = "studentController">
Enter first name: <input type= "text" ng-model = "student.firstName"><br/><br/>
Enter last name: <input type= "text" ng-model = "student.lastName"><br/><br/>
You are entering: {{student.fullName()}}
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.Controller('studentController', function($scope){
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName+ " " + studentObject.lastName;
}
};
});
</script>
结果截图:
对controller
使用小写c
mainApp.controller('studentController', function($scope){
当用户在文本框上输入文本时 {{student.fullName()}} 应该更新。但这是行不通的。有帮助吗?
示例应用程序
<div ng-app = "mainApp" ng-controller = "studentController">
Enter first name: <input type= "text" ng-model = "student.firstName"><br/><br/>
Enter last name: <input type= "text" ng-model = "student.lastName"><br/><br/>
You are entering: {{student.fullName()}}
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.Controller('studentController', function($scope){
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName+ " " + studentObject.lastName;
}
};
});
</script>
结果截图:
对controller
c
mainApp.controller('studentController', function($scope){