When working with a form, I needed to ensure that a string is not empty. If the string is indeed empty, I wanted to set a default value. Otherwise, I wanted to pass the actual value.
Below is the code snippet from the controller:
$scope.addElem = function () {
$scope.lista2.push({
com: null ? com = 'VUOTO' : com = $scope.newItem.com,
gruppo: null ? gruppo = 'VUOTO' : gruppo = $scope.newItem.gruppo
});
};
And here is the corresponding HTML code (Bootstrap is also used):
<form class="form-inline" name="input">
<input type="text" class="form-control col-5" ng-model="newItem.com" placeholder="Nome del comico" ng-keypress="$event.keyCode == 13 && addElem()" />
<input type="text" class="form-control col-5" ng-model="newItem.gruppo" placeholder="Gruppo del comico" ng-keypress="$event.keyCode == 13 && addElem()" />
<button class="btn btn-outline-secondary btn-sm col-2" type="submit" ng-click="addElem()">Inserisci</button>
</form>