L
L
Lenar Mutigullin2017-03-03 13:17:50
Angular
Lenar Mutigullin, 2017-03-03 13:17:50

How to add object to constructor while executing program in Anuglar 2?

I use Autocomplete so that when I enter a value, I get a filtered array, I need to use

this.filteredOptions = this.myControl.valueChanges
         .startWith(null)
         .map(val => val ? this.filter(val) : this.options.slice());

which can be added to the constructor or to ngOnInit so that they can listen to the object.
I would not have a problem if I did not need to output selects with array autocompletion, i.e.
a small example
<div *ngFor="let item of serviceRequest.items; let ind=index">

        <div [ngSwitch]="item.type">
              ....
            <div ngSwitchCase="12">
               <md-input-container>
                 <input mdInput [(ngModel)]="item.text" placeholder="{{form.items[ind].optional_select.label}}"                         [mdAutocomplete]="auto" [formControl]="myControl">
               </md-input-container>

               <md-autocomplete #auto="mdAutocomplete">
                 <md-option *ngFor="let state of item.values | async" [value]="item.text">
                   {{ state.text }}
                 </md-option>
               </md-autocomplete>
             </div>

      </div>

 </div>

where there can be several selects with auto-completion, there was an idea to immediately add, for example, 5 empty spaces to the constructor, and then use them, but this is irrational. I would like to hear your advice on what can be done in this situation)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question