Good, what I try to do is pass 2 values within an array from one component to another, and receive them in the ngOnInit()
function of the child component.
The way I send them from component1 is as follows:
HTML
<button class="boton" type="button" (click)="navegar()"></button>
TS
navegar = function () {
let parametros: any[] = [];
parametros.push(this.var1);
parametros.push(this.var2)
this.router.navigate(['/componente2'], { queryParams: { array: parametros} });
}
And I receive them like this:
TS
ngOnInit() {
this.route.queryParams
.subscribe(params => {
if (params !== {} && params.array[0] === "true") {
this.varAux = params.array[1];
}
})
}
What happens is that when I access component2 without having navigated from component1 , but from another side of the application and ngOnInit()
is executed, I receive params = {}
.
I can not find a way to validate that this object is empty so, that does not enter the if else condition.
Since which property of the queryParams DOM can I validate so that I do not subscribe directly if parameters do not arrive?