angular-formly: Default Values

Kent C. Dodds
InstructorKent C. Dodds
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 5 years ago

angular-formly allows you to default the values of fields for your angular forms using the defaultValue property. To default the value of a field, you can either initialize the model with the default value, or use this defaultValue property on the field configuration.

[00:01] There are two ways to provide a default value for a Formly form. An angular-formly form is simply a representation of the current state of the model. If we were to initialize the model with "First name is Bob," then you see that the form is initialized with that first name being Bob.

[00:18] If, for some reason, you can't programmatically set the model with some default values or you'd just rather store that default value property inside the field configuration itself, then you can simply use the default value property.

[00:34] Then it will initialize the model if that value for this key is not set. If we have "First name is Mary" in here, then that default value will not override the Mary property. That is how you set a default value for an angular-formly form.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today