When the two textboxes are left empty, you will see errors as 'undefined' displayed. These errors disappear once content is entered.
The code I have written looks like this:
Default.aspx
<div ng-app="Welcomecontroller" ng-controller="FullName">
<label>Name:</label>
<input type="text" ng-model="Fornavn" placeholder="Enter a name here">
<input type="text" ng-model="Efternavn" placeholder="Enter a name here">
<hr>
<h1>{{fullName()}}</h1>
</div>
WelcomeController.js
var Welcome = angular.module('Welcomecontroller', []);
Welcome.controller('FullName', function ($scope) {
$scope.fullName = function () {
return "Welcome to " + $scope.Fornavn + " " + $scope.Efternavn;
}
});
If there is no content, it will display like this:
Welcome to undefined undefined
I also attempted to check if the content was empty and handle it accordingly.
WelcomeController.js
var Welcome = angular.module('Welcomecontroller', []);
Welcome.controller('FullName', function ($scope) {
if ($scope.Fornavn != "" && $scope.Efternavn != "") {
$scope.fullName = function () {
return "Welcome to " + $scope.Fornavn + " " + $scope.Efternavn;
}
}
else
{
return "Test";
}
});