Child component doesn't update param @Input when parent component is changing the attribute.
All similar questions I have came across DO NOT solve the problem.
example: The Parent Variable is not updating in the child Component in Angular
or ... https://pretagteam.com/question/angular-child-component-not-updating-after-change-detection
The first time it is created, the property is shared. But when I make a modification from the [(ngModel)] directive (found in the parent), it does NOT propagate the changes to the child component, and therefore the child component does not receive the updated data. (It stays with the previous ones, the ones provided at the beginning).
This is the parent component:
/**
* Created by cnoe la bestia on 13/12/2021
**/
import {Component, OnInit} from '@angular/core';
import {Pedido, Status} from "../shared/“app.model";
import {ActivatedRoute, Router} from "@angular/router";
import {DataService} from "../shared/data.service";
import {ClienteApiRestPedidosService} from "../shared/cliente-api-rest-pedidos.service";
@Component({
selector: 'createPedidoComponent',
templateUrl: './createPedido.component.html',
styleUrls: ['./crearPedido.component.css']
})
export class FatherComponent implements OnInit {
p : string = "p"
pedido: Pedido ={
deliveryAddress: "",
deliveryCity: "",
deliveryPerson: "",
status: Status.Ordered,
} as Pedido;
...
}
and this is the html (part):
...
<fieldset class="form-group">
<div class="col-sm-3">
<label class="control-label" for="idSeller">idSeller</label>
<input type="test" class="form-control"
[(ngModel)]="pedido.idSeller" name="idSeller" >
</div>
</fieldset>
<fieldset class="form-group">
<div class="col-sm-3">
<label class="control-label" for="expectedDeliveryDate">expectedDeliveryDate</label>
<input type="test" class="form-control"
[(ngModel)]="pedido.expectedDeliveryDate" name="expectedDeliveryDate" >
</div>
</fieldset>
<br>
<LineaPedidoComponent [pedido] = "pedido" [cabecera] = "cabecera" [llamada] = "p" > </LineaPedidoComponent>
<br>
...
The child component ts:
/**
* Created by cnoe la bestia on 20/12/2021
**/
import {Component, Input, OnInit} from '@angular/core';
import {LineaPedido, Pedido} from "../shared/“app.model";
import {ClienteApiRestPedidosService} from "../shared/cliente-api-rest-pedidos.service";
import {ActivatedRoute, Router} from "@angular/router";
@Component({
selector: 'LineaPedidoComponent',
templateUrl: './LineaPedido.component.html',
styleUrls: ['./LineaPedido.component.css']
})
export class LineaPedidoComponent implements OnInit {
@Input() pedido : Pedido
@Input() cabecera : boolean | undefined
@Input() llamada :string
id !: number
json: string
constructor(private ClienteApiRestPedidosService: ClienteApiRestPedidosService, private ruta: ActivatedRoute,
private router: Router) {
}
...
}
Any ideas?