I'm used to the older angularjs way of doing select menus and selecting the default value etc and am having trouble wrapping my head around how to do this in Angular (6).
I have a an array of menu items:
fontChoices = [
{
label: 'Trebuchet',
value: "'Trebuchet MS', 'Helvetica Neue', Arial, sans-serif"
},
{
label: 'Georgia',
value: 'Georgia, times, serif'
}
];
and a variable to hold the chosen font: brandFont
My html menu is
<select [(ngModel)]="brandFont"
id="brandFontmenu"
(ngModelChange)="setStyle($event,'--font-family-brand')">
<option *ngFor="let font of fontChoices"
[value]="font.value">{{font.label}}
</option>
</select>
The menu works, displays my fontChoices, and changing the selection fires my function. I can choose Georgia or Trebuchet and the css variable changes and the page updates as it should.
setStyle(e, which) {
document.documentElement.style.setProperty(which, e);
}
On page load, the css variable is set to Trebuchet. Which I can get in ngOnInit with
this.brandFont = String(styles.getPropertyValue('--font-family-brand')).trim();
My question is, how do I get the select menu to display this first choice on page load? I have tried this.brandFont = this.fontChoices[0]; but the menu selected item is empty until something is chosen from the menu.