A warning from Tslint is indicating that the method ngOnChagnes
lifecycle hook should implement OnChanges
. Interestingly, changing ngOnChanges
to OnChanges
resolves the warning.
import { Component, Input, OnInit, Output, EventEmitter, SimpleChange, OnChanges } from '@angular/core';
import { Order } from '../../../../core/orders';
import { CartItem } from '../../../../core/orders';
import { User } from '../../../../core/auth/_models/user.model';
declare var $: any;
@Component({
selector: 'app-order-summary',
templateUrl: './order-summary.component.html',
styleUrls: ['./order-summary.component.scss']
})
export class OrderSummaryComponent implements OnInit, OnChanges {
@Input() cartDetails: Order;
@Input() sellerDetail: User;
@Input() productCost: number;
@Output() closeOrderSummary = new EventEmitter<string>();
@Output() checkoutCart = new EventEmitter<string>();
@Output() updateItemQty = new EventEmitter<string>();
@Output() updateProductSelected = new EventEmitter<string>();
cartList: CartItem[] = [];
isCartEmpty: boolean;
constructor() {}
ngOnChanges(changes: SimpleChange) {
for (const propName in changes) {
if (propName === 'cartDetails') {
const change = changes[propName];
this.cartList = change.currentValue;
this.isCartEmpty = (change.currentValue.length === 0);
}
}
}
ngOnInit(): void {
}
onUpdateItemCount(item, direc) {
const payload = { item, direc };
this.updateItemQty.emit(payload);
}
onUpdateProductSelected(value, item) {
const payload = { value, item};
this.updateProductSelected.emit(payload);
}
goBackToMain() {
this.closeOrderSummary.emit();
}
onCheckoutCart() {
this.checkoutCart.emit();
}
}