I am using an HTML form in my Angular project, but it keeps ignoring the "value" and "selected" parameters. For the first case, I am trying to set the current timestamp as a default value for a datetime-local field.
The HTML code :
<div class="form-group">
<label for="timestamp_honeycomb">Date :</label>
<input type="datetime-local" class="form-control" id="timestamp_honeycomb" formControlName="timestamp_honeycomb" value="{{ timeElapsed | date: 'yyyy-MM-ddTHH:mm' }}" />
</div>
<div class="form-group">
<label for="smell_beehive">Odeur de la ruche</label>
<select name="smell_beehive" class="form-select-sm" id="smell_beehive" formControlName="smell_beehive">
<option value="faible" selected="selected">Faible</option>
<option value="moyenne">Moyenne</option>
<option value="forte">Forte</option>
</select>
</div>
The .ts code of the form :
formGroup = this.formBuilder.group({
timestamp_honeycomb: new FormControl([Validators.required]),
smell_beehive: new FormControl([Validators.required, Validators.pattern(this.regex)]),
)}
Thank you in advance. EDIT : The "selected" part is solved, as I used this format :
smell_beehive: new FormControl('faible',[Validators.required, Validators.pattern(this.regex)])
Yet I remain curious about how to set a default value via the html view.