I have the following scenario:
There are some entities that own Pessoa, one of these is Administrador, so I decided to create a component to wrap the Pessoa data on CRUD forms. I bound the administrador.pessoa property to my new PessoaFormComponent with the @Input() directive.
My problem is that when I submit the AdministradorComponent form, the administrador.pessoa property remains null, like if the updates on pessoa property of PessoaFormComponent were not reflected into AdministradorComponent.
administrador.component.ts:
@Component({
...
templateUrl: './administrador.component.html',
directives: [... PessoaFormComponent, ...],
...
})
export class AdministradorComponent {
@ViewChild('pessoaForm')
pessoaFormComponent: PessoaFormComponent;
}
administrador.component.html:
...
<app-pessoa-form #pessoaForm [(pessoa)]="entidade.pessoa"></app-pessoa-form>
...
pessoa.form.component.ts:
@Component({
...
selector: 'app-pessoa-form',
templateUrl: './pessoa.form.component.html',
...
})
export class PessoaFormComponent implements AfterViewInit {
@Input()
pessoa: Pessoa;
private _tipoPessoa: String;
ngAfterViewInit() {
this._tipoPessoa= 'FISICA';
this.reiniciarPessoa();
}
private reiniciarPessoa() {
if (this._tipoPessoa === 'JURIDICA') {
this.pessoa = new PessoaJuridica();;
} else {
this.pessoa = new PessoaFisica();;
}
}
get tipoPessoa(): String {
return this._tipoPessoa;
}
set tipoPessoa(tipoPessoa: String) {
this._tipoPessoa = tipoPessoa;
this.reiniciarPessoa();
}
}