Skip to content

Can Directive [mdAutocomplete] skip initializing when its attribute value is null? #7069

Closed
@tom10271

Description

@tom10271

Bug, feature request, or proposal:

Proposal

<input [mdAutocomplete]="data.selectOptionsObservables ? auto : null" />

<md-autocomplete 
    #auto="mdAutocomplete"
    *ngIf="data.selectOptionsObservables"
>
    <md-option *ngFor="let option of data.selectOptionsObservables | async" [value]="option.value">
        <span>{{ option.label }}</span>
    </md-option>
</md-autocomplete>

What is the expected behavior?

[mdAutocomplete] should skip initializing if value received is null

What is the current behavior?

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'displayWith' of null
TypeError: Cannot read property 'displayWith' of null
    at MdAutocompleteTrigger._setTriggerValue (material.es5.js:18352)
    at material.es5.js:18187

What are the steps to reproduce?

http://plnkr.co/edit/g2Xp6DuLl0WtY6XZN9bN?p=preview
Please noted the error message is not exactly the same as I have.

What is the use-case or motivation for changing an existing behavior?

I am building a form generator and would like to use Angular/Material2. Some fields require autocomplete only. I tried to achieve it by:

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

@angular/material: 2.0.0-beta.10
Angular: 4.3.6
OS: macOS Sierra 10.12.6
TS: 2.5.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions