Skip to content

docs: Document MdInput focus() method #1486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,25 @@ The divider (line under the `<md-input>` content) color can be changed by using

You can label the `<md-input>` as you would a regular `<input>`.

## Focus

You can put the focus on an input component using the `focus()` method.

### Example

```html
<md-input #nameInput placeholder="name"></md-input>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #nameInput isn't necessary in this example because you're using @ViewChild with the class. I'd omit it so that people don't mistakenly get the impression that a @ViewChild name has to match some template variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I used the ViewChild incorrectly. What I wanted to write was instead:
@ViewChild('nameInput') nameInput: MdInput;
to that this sample still works when multiple md-input are present in the template.
Do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that works too.

```

```ts
export class MyComponent implements OnInit {
@ViewChild('nameInput') nameInput: MdInput;

ngOnInit() {
this.nameInput.focus();
}
}
```

## Full Forms

Expand Down