You can use FormControl from Angular Reactive Form.It is easy.
Angular Docs About Reactive Form
You need to import reactive form
to you module
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
// other imports ...
ReactiveFormsModule
],
})
export class AppModule { }
Than you need to create FormControl in you component.ts
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-name-editor',
templateUrl: './name-editor.component.html',
styleUrls: ['./name-editor.component.css']
})
export class NameEditorComponent {
name = new FormControl('');
}
After this you need to set Form control to your element select
in html
<select [formControl]="name">
<option value="null">No Default Layout</option>
<option *ngFor="let l of availableLayouts" [value]="l.id">
{{l?.name}}
</option>
</select>
If you need default value of select you must create formControl with value for example:
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-name-editor',
templateUrl: './name-editor.component.html',
styleUrls: ['./name-editor.component.css']
})
export class NameEditorComponent {
name = new FormControl(null);
}
///(you can pass any to new FormControl(0), or new FormControl(false), new FormControl('string'))
In this case default value for select will be null.And options with value null will be selected in dropdawn.
In you case new FormControl(0)
as default value.