Skip to content

Focusing on md-input-container programatically #2983

@vadim82

Description

@vadim82

I have a component that has some md-input-container elements. I would like to set focus on the first one when the view loads.

The way I am implementing this is by creating a @ViewChild property and then calling focus on it ngAfterViewInit. There are no errors but, the focus is still not working.

export class AdminUserComponent implements AfterViewInit {
    @ViewChild(MdInputContainer)
    private firstInput: MdInputContainer;

    ngAfterViewInit() {
        this.firstInput._mdInputChild.focus();
    }
}

I tried setting the focus code in a setTimeout function but that didn't make a difference. Has anyone successfully set focus on a material input when the view loads?

Metadata

Metadata

Assignees

No one assigned

    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