I'm trying to leave one of the option elements as selected, but I can not put it to work on Angular 6.
app.component.html:
<select [(ngModel)]="marcaSelecionada" class="form-control" name="marca" required>
<option value="">Selecione uma marca...</option>
<option *ngFor="let marca of marcas" [ngValue]="marca.id">{{ marca.nome_marca | uppercase }}</option>
</select>
app.component.ts:
import { Component, OnInit } from '@angular/core';
import { AtualizaFormularioService } from './atualiza-formulario.service';
interface MarcaModelo {
id?: string;
nome_marca?: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
public marcas: MarcaModelo[];
public campoMarca: MarcaModelo = {
nome_marca: ''
}
public marcaSelecionada: string = '2';
}