Within my angular 4 project, I am facing the challenge of setting a value in an input field and in a MatSelect without relying on any binding.
Here is the HTML structure:
<div class="row search-component">
<div class="col-md-5 no-padding-right">
<mat-form-field>
<mat-select placeholder="searchfor" id="selectedFilter" name="propertyList" #selectedFilter>
<mat-option *ngFor="let property of propertyList" [value]="property">
{{property.label}} </mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="col-md-7 no-padding-left">
<mat-form-field>
<input matInput placeholder="search" id="searchfield" name="searchfield" #selectedValue>
<mat-icon class="pointer" matSuffix>search</mat-icon>
</mat-form-field>
</div>
</div>
Upon clicking a button, I need to populate a Mat-option and set a value in the input field dynamically.
Below is the method responsible for setting these values:
setField(chipSelected: Filter) {
this.filter = chipSelected;
document.getElementById('searchfield').focus();
document.getElementById('searchfield').value = 'somevalue'; <-- The challenge lies here
}
I'm encountering difficulty in accessing the value. Why is this happening? And what can be done to resolve it?