Issue
I have one select that i need to put a default select option, but it's not showing in my template.
I tried:
<div class="select">
<select (change)="calculaMes(mesEscolhido)" [(ngModel)]="mesEscolhido" name="selectMesEscolhido"
class="select-text">
<option class="dropdown-item" disabled selected value>Teste</option>
<option [hidden]="datasComMovimentacoes[x].data == mesEscolhido" *ngFor="let mes of datasComMovimentacoes;let x = index"
class="dropdown-item">{{mes.data}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
I don't believe this is caused by my css, but, this is my css:
.select {
font-family:
'Roboto','Helvetica','Arial',sans-serif;
position: relative;
width: 100%;
margin-top: 5%;
font-size: 18px;
color: #757575!important;
}
.select-text {
margin-top: 10%;
position: relative;
font-family: inherit;
background-color: transparent;
color: #757575!important;
width: 100%;
font-size: 18px;
border-radius: 0;
border: none;
border-bottom: 1px solid rgba(0,0,0, 0.12);
}
/* Remove focus */
.select-text:focus {
outline: none;
color: #757575!important;
border-bottom: 1px solid rgba(0,0,0, 0);
}
/* Use custom arrow */
.select .select-text {
appearance: none;
color: #757575!important;
-webkit-appearance:none
}
This is my result in template:
Solution
The default option will be selected if the value
attribute of the option tag is set to the default value of the selectedOption
property on your Component. Let's say you didn't initialize the selectedOption
property, then by default it's value will be undefined
. And so, this value
attribute of the option
tag should be undefined
in that case.
...
<option class="dropdown-item" disabled selected value="undefined">Select an Option</option>
...
Here's a Sample StackBlitz for your ref.
Answered By - SiddAjmera
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.