此angularJS代码有什么问题?它不起作用。
这一行存在一些问题:
You are entering: {{student.fullName()}}
完整代码如下:
<html>
<head>
<script type = "javascript" src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</head>
<body>
<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: "ABCD",
lastName: "EFGH",
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
}
});
</script>
</body>
</html>
答案 0 :(得分:1)
角度文件被认为是文本文件而不是JavaScript文件。请将其更改为以下代码:
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
答案 1 :(得分:0)
错误在于引用 使用
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>