The following Angular 2 (version 4.3.5) code does not work as expected.
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
crossorigin="anonymous">
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous">
</script>
<form style="margin:50px;">
<div class="form-control">
<label for="firstName">First Name</label>
<input
ngControl="firstName"
id="firstName"
#firstName
type='text'
class='form-control'
required>
<div
class="alert alert-danger"
*ngIf="!firstName.valid && firstName.touched">
A first name is required
</div>
</div>
<br/>
<button class="btn btn-primary" type="submit">
Submit!
</button>
</form>
When the ngIf
statement is
*ngIf="!firstName.valid"
the error message div
is shown when the page is loaded and remains visible after text has been entered into the input.
When the ngIf
statement is as above
*ngIf="!firstName.valid && firstName.touched"
the error message is not shown.
What am I missing? thank you A.G.