Skip to content

Instantly share code, notes, and snippets.

@bharat-tiwari
Last active March 14, 2018 16:56
Show Gist options
  • Save bharat-tiwari/567516dd2d741fdf2033a736f4577769 to your computer and use it in GitHub Desktop.
Save bharat-tiwari/567516dd2d741fdf2033a736f4577769 to your computer and use it in GitHub Desktop.
Item details component using ngOnChanges
import {Component,Input, OnChanges, SimpleChanges, SimpleChange} from '@angular/core';
@Component({
selector: 'item-details',
templateUrl: 'item-details.html',
})
export class ItemDetails implements OnChanges {
private _item;
get item(): any {
return this._item;
}
@Input()
set item(val: any) {
console.log('previous item = ', this._item);
console.log('currently selected item=', val);
this._item = val;
this._item.status = 'In Process';
}
@Input() notifyItemProcessed: () => void;
suppliedQuantity: number;
scannedUPC: string;
errors: string[];
constructor(){}
ngOnChanges(changes: SimpleChanges) {
const currentItem: SimpleChange = changes.item;
console.log('prev value: ', currentItem.previousValue);
console.log('got item: ', currentItem.currentValue);
if(currentItem.currentValue){
this.scannedUPC = changes.item.currentValue.upc;
}
this.suppliedQuantity = 0;
}
..
..
..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment