Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 962 of the free egghead.io lessons, plus get Angular 1.x content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

angular-formly: Default Values

0:52 Angular 1.x lesson by

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.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

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.

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.

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.

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?