I'm trying to select an element in a parent component, from a child component.
In my child component I have the following code:
removeItem(outcome) {
const el = (<HTMLInputElement>document.getElementById(outcome.id));
el.classList.remove("selected-bet");
//...
}
and the item I am trying to select is the id (outcome.id) that is in the parent component:
<ng-container *ngFor="let outcome of market.Outcomes">
<div class="market-cell-3" id="{{outcome.id}}">
<span class="market-name">{{ outcome.name}}.</span>
</div>
</ng-container>
When I try the above code, el is always null and I get the following error
BetSlipComponent.html:78 ERROR TypeError: Cannot read property 'classList' of null
What is the correct way to do this?
To give some more details about the structure of the app: The parent controller displays a list of sporting markets, and the child component is like a shopping cart. When a user selects a market in the parent, a class is added (selected-bet) and it is added to the cart. There is a remove button (removeItem(outcome)) in the cart and its from there I am experience the problem.