I am using ngx-bootstrap to implement a typeahead feature on an input field.
<input type="text" class="form-control with-icon" placeholder="Address ..."
formControlName="address" [typeahead]="addressDataSource" typeaheadOptionField="fullAddress" />
Here is how my addressDataSource is structured :
[
{
id: '1',
fullAddress: '44000 - Nantes'
},
{
id: '2',
fullAddress: '77400 - Paris'
}
....
]
The issue I am facing is that when I select a value, the input field shows the fullAddress correctly. However, I want the actual value of the input field to be only the postal code (e.g. 44000 or 77400).
I attempted to create a Directive as follows :
constructor(private model: NgControl) { }
@HostListener('input') inputChange() {
const newValue = this.model.value.split(' ')[0];
this.model.control.setValue(newValue);
this.model.valueAccessor.writeValue(this.model.value);
}
While the value does change, the displayed value in the input field also changes.