I have a page where I am populating invoices into a grid. In the grid there is an option to view the payments for a particular invoice. The button switches the user from the invoices page to the payments page where it then filters all the payments so that only the payment that corresponds to that particular invoice will show up. Also, when clicking on the payments page itself, it populates all payments into a grid. I have both of these things accomplished in the ngOnInit() method, however, I need to be able to switch between the two. In other words, I want to filter the payments when a user clicks the button on the invoices page and when a user clicks on the payments tab in the navbar I want it to show all payments. So, I have tested both subscriptions and know they work, but how can I switch between the two subscriptions to accomplish this? Any help is appreciated.
I have played around with different variables and equality checks in the if statement and have even tried changing the line location of the if statement but to no prevail
ngOnInit() {
this.sub = this.route.params.subscribe(
params => {
if (params == null) { //HERE LIES THE ISSUE
this.invoiceNum = params['invoiceNum'];
//displays FILTERED payments
this.paymentService.showPayments(this.invoiceNum).subscribe(
res => {
this.payments = res.value;
this.loading = false;
console.log(res);
},
err => {
if (err.status == 401) {
this.auth.logOut();
}
this.loading = false;
console.log(err);
}
);
} else {
//displays ALL payments
this.paymentService.getPayments().subscribe(
res => {
this.payments = res.value;
this.loading = false;
console.log(res);
},
err => {
if (err.status == 401) {
this.auth.logOut();
}
this.loading = false;
console.log(err);
}
);
}
}
);
}