Search code examples
htmlangulartypescriptautocompletematerialize

Autocomplete materialize, search, filter. Angular


In the following code, I want to use the search inside option, like autocomplete. How can I do that?

  <div class="row">
        <div class="input-field col s12">
          <select formControlName="sensorType_id" id="sensorType_id" materialize="material_select" [materializeSelectOptions]="sensorstype">
            <option value="" disabled selected>Select Sensor Type</option>
            <option *ngFor="let sensortype of sensorstype" [value]="sensortype.sensorType_id">{{sensortype.sensordescription}}</option>
          </select>
        </div>
      </div>

Solution

  • You can do like this

    <div class="row">
            <div class="input-field col s12">
                <md-input-container class="full-width">
                    <input mdInput placeholder="Location *" [mdAutocomplete]="autoSensore"
                           #searchLocation
                           formControlName="sensorType"
                           (keyup)="onChangeLocationName()">
                </md-input-container>
                <md-autocomplete #autoSensore="mdAutocomplete">
                    <md-option
                            *ngFor="let sensortype of sensorstype | search: searchLocation.value"
                            [value]="sensortype.sensordescription"
                            (onSelectionChange)="onSelected($event.source.selected, sensortype.id)">
                        {{ location.name }}
                    </md-option>
                </md-autocomplete>
            </div>
        </div>
    

    you need to create search pipe also