0

libros.component.ts

export class LibrosComponent implements OnInit {
          public order;
          ...

libros.component.html

<div class="form-group">
          <label for="selectOrden">Ordenar</label>
          <select class="form-control input-sm" #ordenar="ngModel" [(ngModel)]="order" name="ordenar" id="selectOrden" (change)="findOrder()">
              <option>Alfabético</option>
              <option>Fecha</option>
              <option>Valoración</option>
          </select>
 </div>

When the page is loaded this select is like this:

enter image description here But I want a default value, like this:

img01 I also have tried with selected="selected", but it doesn't work here.

Thanks

2
  • Possible duplicate of Angular: set selected value for <select> Commented Aug 27, 2017 at 17:55
  • @Jose you should not add "solved" in title, if an answer works for you, instead you should accept it (green check next to answer) see tour Commented Aug 27, 2017 at 18:14

1 Answer 1

1

Just initialize the field order with the value you want to display in the constructor or ngOnInit() method.

Sign up to request clarification or add additional context in comments.

Comments

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.