The inputs are inside of a modal dialog. I have no idea why it is not working. I looked at the official docs and it listed focus as something you can pass to the element but it's not working?
Does anyone know why?
Angular Material - Input Docs
<form class="example-form">
<md-input-container class="example-full-width" style="width: 300px; padding: 5px; border-radius: 10px;">
<input mdInput type="email" name="to" placeholder="Email">
<md-error></md-error>
</md-input-container>
<md-input-container focus focused>
<input mdInput type="text" name="a" placeholder="zzzz" focus focused (focus)="">
</md-input-container>
</form>
Your attempts do not work because:
focused
is a property driving the mat-focused class on mdInputContainer
. You can use it to know whether your input is focused or not. You cannot use it to change the focus state.focus
is a method on mdInput
that lets you programmatically focus the input. You can call the myInput.focus()
with myInput
being something like ViewChild('myInput')
for instance. But the simplest way to achieve what you want is to use the standard autofocus
attribute :
<md-input-container>
<input mdInput type="text" name="a" placeholder="zzzz" autofocus>
</md-input-container>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With