I'm new to AngularJS and was just playing around with the stuff. Here is my HTML:
<div ng-app ng-controller="nameController">
<input type="text" value="Jack" ng-model="fname" />
<input type="text" value="Sparrow" ng-model="lname" />
{{getFullName()}}
</div>
<input type="text" value="Hello" />
And here is the controller code:
function nameController($scope) {
$scope.getFullName = function () {
return $scope.fname + " " + $scope.lname;
};
}
I have set the value of the input text fields using the value
attribute. So I expected the controller function getFullName
to read those values and return the full name on page load. But what I get is:
undefined undefined
And the input text boxes empty. Why is it so?