As I continue my journey of learning Angular, I am encountering a challenge that has me stuck. In one component, I have three values that I need to pass to another component. While I have a basic grasp of observables and subscriptions, I have only worked with passing 1 parameter in the past. Now, I find myself wanting to broadcast 3 values simultaneously.
Let's take a look at my shopping cart code:
additem(itemText){
this.cart.push(itemText);
this.itemscount = this.cart.length;
this._data.changeCart(this.cart);
}
Every time I click on a product, the above function is triggered, sending the 'cart' array to an observable where it is then broadcasted.
export class DataService {
private cart = new BehaviorSubject<any>([]);
cast = this.cart.asObservable();
constructor() { }
changeCart(item_param) {
this.cart.next(item_param);
//console.log(this.cart);
}
}
Now I am faced with the dilemma of how to pass 3 values through the observable. I have come across the idea of packaging all three values into an array and passing that along, but I am unsure about how to store multiple values within a single array in Angular.
I would greatly appreciate any assistance or guidance on this matter. Thank you!