Skip to content

MdAutocomplete Throws error on dynamic focus #4844

@hemantjadon

Description

@hemantjadon

Bug, feature request, or proposal:

Bug: The MdAutocomplete throws the error

FeedHeaderComponent.html:12 ERROR TypeError: Cannot read property 'template' of undefined
    at MdAutocompleteTrigger._createOverlay (material.es5.js:18786)
    at MdAutocompleteTrigger.openPanel (material.es5.js:18550)
    at Object.eval [as handleEvent] (FeedHeaderComponent.html:12)
    at handleEvent (core.es5.js:11852)
    at callWithDebugContext (core.es5.js:13060)
    at Object.debugHandleEvent [as handleEvent] (core.es5.js:12648)
    at dispatchEvent (core.es5.js:8830)
    at core.es5.js:9419
    at HTMLInputElement.<anonymous> (platform-browser.es5.js:2674)
    at ZoneDelegate.invokeTask (zone.js:398)
    at Object.onInvokeTask (core.es5.js:4136)
    at ZoneDelegate.invokeTask (zone.js:397)
    at Zone.runTask (zone.js:165)
    at HTMLInputElement.ZoneTask.invoke (zone.js:460)
    at FeedComponent.webpackJsonp.183.FeedComponent.focusTextbox (feed.component.ts:67)

When I try to dynamically focus the textbox using ElementRef

ngOnInit() {
this.elementRef.nativeElement.querySelector('feed-header input#search').focus();
}

What is the expected behavior?

The MdAutocomplete should not crash when the focus is brought to the application.

What is the current behavior?

The MdAutocomplete crashes the application with the above stack trace

What are the steps to reproduce?

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

http://plnkr.co/edit/4gdaiKeAon2ziXJ9AOd1

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

This is the common use case for the application to have the dynamic focus when the a

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

Angular v4.0.0

Is there anything else we should know?

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