I am currently trying to validate a card with AngularJS. This works fine until the user deletes all the inputted data from the input field, then it throws the following errors:
angular.js:11004 undefined is not an object (evaluating '$scope.card.length')
My HTML Code:
<input type="text" class='form-control' id='card' ng-model="card" ng-change="validateCard()" required>
JavaScript code that throws the error when the input is empty:
$scope.validateCard = function() {
// Get card type
if ($scope.card.length) { // <-- throws the error
[...]
I also tried
if ($scope.card.length !== undefined) {
but it didn't help.
$scope.cardmight as well be undefined.if($scope.card && $scope.card.length)maybe?if ($scope.card && $scope.card.length) ...