Skip to content

Commit

Permalink
fix(dynamic-form-group): Remove hard dependencies of class-transforme…
Browse files Browse the repository at this point in the history
…r, for use alternative class mapper using the decorators
  • Loading branch information
EndyKaufman committed Feb 28, 2018
1 parent 047458f commit 8aff1c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 1,6 @@
import { FormBuilder } from '@angular/forms';
import { DynamicFormGroup } from './dynamic-form-group';
import 'reflect-metadata';
import { classToClassFromExist, classToClass } from 'class-transformer';

export class DynamicFormBuilder extends FormBuilder {
group<TModel>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata';
import { MetadataStorage, Validator, getFromContainer, ValidationTypes, validateSync, ValidationError } from 'class-validator';
import { FormControl } from '@angular/forms';
import { plainToClass, classToClassFromExist, plainToClassFromExist, classToClass } from 'class-transformer';
import { classToClass } from 'class-transformer';
import 'reflect-metadata';

export class DynamicFormGroup<TModel> extends FormGroup {
Expand Down Expand Up @@ -169,7 169,7 @@ export class DynamicFormGroup<TModel> extends FormGroup {
return newFields;
}
get object() {
const object = this._object ? classToClass(this._object) : new this.factoryModel();
const object = this._object ? classToClass(this._object, { ignoreDecorators: true }) : new this.factoryModel();
if (object !== undefined) {
Object.keys(this.controls).forEach(key => {
if (this.controls[key] instanceof DynamicFormGroup) {
Expand All @@ -179,19 179,13 @@ export class DynamicFormGroup<TModel> extends FormGroup {
}
});
}
return plainToClass(
this.factoryModel,
object
);
return new this.factoryModel(object);
}
set object(object: TModel) {
if (object instanceof this.factoryModel) {
this._object = classToClass(object);
this._object = classToClass(object, { ignoreDecorators: true });
} else {
this._object = plainToClass(
this.factoryModel,
object as Object
);
this._object = new this.factoryModel(object as Object);
}
Object.keys(this.controls).forEach(key => {
if (this.controls[key] instanceof DynamicFormGroup) {
Expand Down

0 comments on commit 8aff1c4

Please sign in to comment.