I'm passing a values from one component to the other:
paquete-detalle.component.ts
nombre: string;
precio: number;
ngOnInit() {
const id = this.activatedRoute.snapshot.paramMap.get('id');
this.fs.getPaqueteObject(id).valueChanges().subscribe(paquete => {
this.nombre = paquete.nombre;
this.precio = paquete.precio;
});
}
paquete-detalle.component.html
{{nombre}} {{precio}} //All good with these values, if they are printed.
<app-reserva [precio]="precio" [nombre]="nombre"></app-reserva>
Then in reserva.component.ts I have the following:
@Input() precio: number;
@Input() nombre: string;
constructor( private fs: FirebaseService, private fb: FormBuilder, ) {
this.forma = fb.group ({
nombre: [ this.nombre ],
precio: [ this.precio ],
});
}
ngOnInit() {
console.log(this.precio, this.nombre);
}
This is where I try to save it in a reactive form but I get null
( undefined
in the console) as a result of this.price
and this.name
.
However, in reserva.component.html if the values are printed:
<div class="text-center">
<h4>{{nombre}}</h4>
<p>Desde: USD {{precio}} / persona</p>
</div>
What is the correct way to pass the values between components?