1
@Component({
    selector: 'filter',
    template: "<select [(ngModel)]="filterState" (change)="selected()">
<option value="">All</option>
                <option *ngFor="let s of states "   [ngValue]="s">{{ s.label}}</option>
            </select>",
});

export class FilterComponent { 
   private states = [
      {
        value: 'active',
        label: 'Active',
      },
      {
        value: 'done',
        label: 'Done',
      },
      {
        value: 'removed',
        label: 'REMOVED',
      }
    ];

  private filterState         =   '';
  selected() :void {
     //this.filterState is still the initiated value
  }
}

In the above case the "All" option is not shown and also whenever changing the option the ngModel it isn't updated.

Tried with value instead of ngValue , and also tried with a private filterState = 0; but same happens here

1 Answer 1

1

I think you need

[ngValue]=""

instead of mixing value and [ngValue]

[value]="s" won't work because [value] only supports strings but not objects.

Sign up to request clarification or add additional context in comments.

3 Comments

Still the same problem
Can you provide a Plunker that allows to reproduce?
Yes i see the suggested method from you working great in plunker , my code is in angular rc 5 may be that causes , let me check , thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.