Skip to content

Instantly share code, notes, and snippets.

@mdmoin7
Last active August 29, 2019 04:08
Show Gist options
  • Save mdmoin7/70633123bd75a18051d20f9c6cbb1fc0 to your computer and use it in GitHub Desktop.
Save mdmoin7/70633123bd75a18051d20f9c6cbb1fc0 to your computer and use it in GitHub Desktop.
<app-product [pData]="pList" (addItem)="saveToCart($event)"></app-product>
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Product } from 'src/app/models/product';
@Component({
selector: 'app-product',
template: `
<div>
<img [src]="pData.productImage" />
<h3>{{ pData.productName }}</h3>
<h4>{{ pData.productPrice }}</h4>
<button (click)="addToCart()">Add to Cart</button>
</div>
`,
styleUrls: ['./product.component.css']
})
export class ProductComponent {
@Input() pData: Product = null;
@Output() addItem=new EventEmitter();
addToCart(){
this.addItem.emit(this.pData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment