Skip to content

Commit b9cf19b

Browse files
alvarocamillontjhosefmarks
authored andcommitted
fix(page-dynamic-edit): corrige importação do DynamicForm
O formulário dynamicForm não era carregado corretamente causando o seguinte erro ERROR TypeError: Cannot read property 'form' of undefined quando usuário selecinonava as opções de salvar ou salvar novo Alterada a importação do ViewChild utilizando a flag static como false Ver (https://angular.io/api/core/ViewChild)
1 parent 338dfd0 commit b9cf19b

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

projects/templates/src/lib/components/po-page-dynamic-edit/po-page-dynamic-edit.component.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
3-
import { FormsModule } from '@angular/forms';
3+
import { FormsModule, NgForm } from '@angular/forms';
44
import { HttpClientTestingModule } from '@angular/common/http/testing';
55
import { RouterTestingModule } from '@angular/router/testing';
66

@@ -13,6 +13,7 @@ import { configureTestSuite, expectPropertiesValues } from './../../util-test/ut
1313

1414
import { PoPageDynamicEditComponent } from './po-page-dynamic-edit.component';
1515
import { PoPageDynamicEditActions } from './po-page-dynamic-edit-actions.interface';
16+
import { PoDynamicFormStubComponent } from './test/po-dynamic-form-stub-component';
1617

1718
describe('PoPageDynamicEditComponent: ', () => {
1819
let component: PoPageDynamicEditComponent;
@@ -28,7 +29,8 @@ describe('PoPageDynamicEditComponent: ', () => {
2829
],
2930
providers: [],
3031
declarations: [
31-
PoPageDynamicEditComponent
32+
PoPageDynamicEditComponent,
33+
PoDynamicFormStubComponent
3234
],
3335
schemas: [ NO_ERRORS_SCHEMA ]
3436
});
@@ -45,6 +47,15 @@ describe('PoPageDynamicEditComponent: ', () => {
4547
expect(component).toBeTruthy();
4648
});
4749

50+
it('should set dynamicForm ViewChild properly', () => {
51+
const form: NgForm = {
52+
dirty: true
53+
} as NgForm;
54+
55+
component.dynamicForm.form = form;
56+
expect(component.dynamicForm.form.dirty).toBeTruthy();
57+
});
58+
4859
describe('Properties: ', () => {
4960

5061
it('p-actions: should set property with valid value', () => {

projects/templates/src/lib/components/po-page-dynamic-edit/po-page-dynamic-edit.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ export class PoPageDynamicEditComponent implements OnInit {
251251
/** Título da página. */
252252
@Input('p-title') title: string;
253253

254-
@ViewChild('dynamicForm', { static: true }) dynamicForm: PoDynamicFormComponent;
255-
@ViewChild('gridDetail', { static: true }) gridDetail: PoGridComponent;
254+
@ViewChild('dynamicForm', { static: false }) dynamicForm: PoDynamicFormComponent;
255+
@ViewChild('gridDetail', { static: false }) gridDetail: PoGridComponent;
256256

257257
constructor(
258258
private router: Router,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component } from '@angular/core';
2+
import { NgForm } from '@angular/forms';
3+
import { PoDynamicFormComponent } from '@portinari/portinari-ui';
4+
5+
@Component({
6+
selector: 'po-dynamic-form',
7+
template: '',
8+
providers: [
9+
{
10+
provide: PoDynamicFormComponent,
11+
useClass: PoDynamicFormStubComponent
12+
}
13+
]
14+
})
15+
16+
export class PoDynamicFormStubComponent {
17+
18+
private _form: NgForm;
19+
20+
get form(): NgForm {
21+
return this._form;
22+
}
23+
24+
set form(form: NgForm) {
25+
this._form = form;
26+
}
27+
}

0 commit comments

Comments
 (0)