27 lines
717 B
Plaintext
27 lines
717 B
Plaintext
@implements IDisposable
|
|
@inject IShoppingCartService shoppingCartService
|
|
|
|
<a href="ShoppingCart" class="btn btn-info">
|
|
<i class="oi oi-cart"></i> Cart
|
|
<span class="badge bg-dark">@shoppingCartItemCount</span>
|
|
</a>
|
|
|
|
@code {
|
|
private int shoppingCartItemCount = 0;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
shoppingCartService.OnShoppingCartChanged += ShoppingCartChanged; //subscribe to event
|
|
}
|
|
|
|
protected void ShoppingCartChanged(int totalQuantity){
|
|
shoppingCartItemCount = totalQuantity;
|
|
StateHasChanged();
|
|
}
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
shoppingCartService.OnShoppingCartChanged -= ShoppingCartChanged; //subscribe from event
|
|
}
|
|
}
|