Focusing on md-input-container programatically
See original GitHub issueI 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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Programmatically focus and select angular2 material design ...
You can use the focus method from the md-input component as shown in the documentation. https://material.angular.io/components/input/api
Read more >Demos > Input - AngularJS Material
The md-input-container gives you the flexibility to display your messages using many standard angular directives. For instance, toggle the switch to the ...
Read more >Angular 2 Material input focus not working – iTecNote
focus is a method on mdInput that lets you programmatically focus the input. You can call the myInput.focus() with myInput being something like...
Read more >Angular2/material 2: md-input-container label is not resetting ...
Coding example for the question Angular2/material 2: md-input-container label is not resetting float when value is changed programmatically-angular.js.
Read more >Angular Material - Quick Guide - Tutorialspoint
The md-autocomplete, an Angular Directive, is used as a special input control ... to show a container component which can be shown or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for helping me. I found my problem… I tried with
MdInput
and it didnt work. Then I tried withMdInputDirective
and now it works perfectly.I just linked you the source code of
md-input-container
, there is nofocus()
method, nor does the documentation say anything about anyfocus()
method on theMdInputContainer
https://material.angular.io/components/component/inputAnd it seems to be working to me when I focus the input http://plnkr.co/edit/fVQshe6iwOMpDZNd8HCH?p=preview