function studentController($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
}
<html>
<head>
<title>Angular JS Controller</title>
</head>
<body>
<h2>
AngularJS Sample Application</h2>
<div ng-app="" 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 src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
</body>
</html>
爲什麼我沒有得到全名? 我做錯了嗎?
必須聲明的模塊將在'NG-app'或使用'angular.bootstrap '在你的代碼中的某處。否則,你的應用程序不被視爲一個Angular應用程序。 – ValLeNain