Basic usage
NgxFormObjectModule
#
1. Import To start using ngx-form-object you have to import NgxFormObjectModule
into the root module of your project.
#
2. Create a modelThe model will be used to populate the form.
The model must specify which properties are attribute properties (his own properties), which are belongsTo properties, and which properties are hasMany properties. For those puproses Attribute
, BelongsTo
, and HasMany
decorators are exposed.
#
3. Create a form object classThe task of a specific form object is to manage forms of a specific type.
#
4. Create a form store (form)FormObject
is created out of the model. To create a FormStore
out of that FormObject
, inject or instatiate a FormObjectBuilder
in your component/service.
Use FormObjectBuilder.create
to create the FormStore
.
#
5. Map form store to the templateImport ReactiveFormsModule
to the parent module.
Form store can be used in a template in the same way as any other form created by Angular's FormBuilder
.
#
6. Implement a saving functionalityTo save the form (model), .save()
on a FormStore
instance should be used.
In the background, beforeSave
, save
, and afterSave
hooks from FormObject are called. Out of those three, only the save
function is mandatory (unless the saving functionality is not used).