Last active
March 14, 2018 16:56
-
-
Save bharat-tiwari/567516dd2d741fdf2033a736f4577769 to your computer and use it in GitHub Desktop.
Item details component using ngOnChanges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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