question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChipList and Autocomplete does not display programmatically set model

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Programmatically setting the model on a mat-input associated with both a mat-chip-list and mat-autocomplete should display the model value in the input.

What is the current behavior?

The value is not displayed in the input. Works when only a mat-chip-list or mat-autocomplete is associated with the mat-input but not both.

What are the steps to reproduce?

http://plnkr.co/edit/n0vabloWOJwnGvjyWXAY

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular Material Beta 12 Angular 4.4.6

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
basti1253commented, Jan 7, 2018

I’ve hit the same issue. Instead of using an ngModel I used a FormControl. Resetting the FormControl value from within ChipInput change event works. Whenever I reset the FormControl value from within autocomplete.optionSelected callback the control value updates, but not the displayed value. I prepared a plunker to demonstrate this, too: https://plnkr.co/edit/dIpxrl?p=preview

As a workaround I reset the value directly on the input element.

4reactions
tinayuangaocommented, Feb 23, 2018

The reason is both mat-chip-list and input are MatFormFieldControl, and when you put mat-chip-list in front of input, mat-chip-list is used in form-field and the input will not get the model value. A workaround is putting input before mat-chip-list in html:

  <p>
    <mat-form-field>
       <input matInput type="text" [matChipInputFor]="chipList1" placeholder="Input with Chip List and Autocomplete" [(ngModel)]="model1" [matAutocomplete]="auto1" />
        <mat-chip-list #chipList1>
            <mat-chip *ngFor="let c of chips">
                {{c.text}}
                <mat-icon matChipRemove>cancel</mat-icon>
            </mat-chip>
        </mat-chip-list>
       
    </mat-form-field>
    <mat-autocomplete #auto1="matAutocomplete" [displayWith]="displayWith">
        <mat-option *ngFor="let o of options" [value]="o">
            {{o.text}}
        </mat-option>
    </mat-autocomplete>
  </p>
Read more comments on GitHub >

github_iconTop Results From Across the Web

ChipList and Autocomplete does not display programmatically ...
Programmatically setting the model on a mat-input associated with both a mat-chip-list and mat-autocomplete should display the model value ...
Read more >
Programmatically set model with ChipList and Autocomplete
Configure SystemJS --> <script src="systemjs.config.js"></script> <script> ... Submit marks the input as invalid, but does not show the error message until ...
Read more >
How to programmatically update a MatChipList?
I have the following control using mat-chip-list . Once the user enters a few chips in the list and data is saved, I...
Read more >
Chips - Angular Material
When a chip is not selectable, changes to its selected state are always ignored. By default an option chip is selectable, and it...
Read more >
Chips Autocomplete - StackBlitz
<mat-form-field class="example-chip-list">. <mat-chip-list #chipList aria-label="Fruit. selection">. <mat-chip. *ngFor="let fruit of fruits".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found