Guides
GuidesExamplesGitterLog In
Guides

formly-focus

directive

🚧

Internal Directive

Even though you have access to use this directive, general use of angular-formly suggests that you shouldn't have to use it. This directive is automatically added by the ngModelAttrsTemplateManipulator. Note, because this is an internal directive, it's API is subject to change without a major version change. You've been warned!

This is an attribute directive. It will watch the given value and focus the element when the given value is truthy. You can also optionally add a refocus attribute and this will cause focus to be returned to the previous element with focus when the formly-focus value is set to falsey (unless the user has clicked away from the focused element).

<input ng-model="model[options.key]"
       formly-focus="{{options.templateOptions.focus}}"
       focus-wait="0"
       refocus
       />
Attribute NameData TypeDescription
formly-focusstring of 'true' or 'false'setting this value to 'true' will focus on the element, setting it to 'false' will blur the element (if it's still the document.activeElement).
focus-waitstring of integerThere's a timeout setup for focusing the active element. Defaults to 0.
refocusN/AAdding the refocus attribute will cause this directive to keep track of the previous element with focus and refocus on the previous one.

Note: Here's an example of how to take full advantage of this directive in your field config. You'll notice that focus-wait and refocus isn't exactly straightforward. Please file an issue if you have a use-case for this and I can make it easier.


Sponsor