1

I have the following select in my template:

   <select class="form-control" formControlName="tipo" name="tipo">
       <option value="" selected disabled>(Select an option)</option> 
        <option value="FACT">Factura</option>
        <option value="NOCRE">Nota Crédito</option>
   </select>

however, despite I have put the selected directive to the first one, it does not show if the user does not click the select. It behaves like another option tag.

How can I make this option visible when the component loads without user interaction?

0

2 Answers 2

2

Since value is "" for 'Select..' option, set value "" in it's formcontrol

Working Demo

Try like this:

this.yourForm= new FormGroup({
    'tipo':new FormControl(''),
});
Sign up to request clarification or add additional context in comments.

Comments

0

why not Adding a model :

in your class :

tipo: string = "";

in HTML :

 <select [(ngModel)]="tipo" class="form-control">
       <option value="" selected disabled>(Select an option)</option> 
        <option value="FACT">Factura</option>
        <option value="NOCRE">Nota Crédito</option>
   </select>

3 Comments

Reactive form and Template driven form shouldn't be mixed
Some else hate me Hahaha
Haha.. Check my answer in this: (Downvote for no reason) stackoverflow.com/questions/58009811/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.