RKh RKh - 3 months ago 8
AngularJS Question

Code not working

What is the issue with this angularJS code? It is not working.

This line has some issue:

You are entering: {{student.fullName()}}


Complete code is as below:

<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>

Answer

Error is in referencing Use

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
Comments