2017-10-06 52 views
0

我输入的装饰看起来像这样我如何将多个参数传递给@input装饰功能角4

@Input() 
    filler(itemName:any,itemRate:number,itemQty:number,itemDiscount:number,itemSubtotal:number) 
{ 
this.cart.push({name:itemName,rate:itemRate,qty:itemQty,discount:itemDiscount,subtotal:itemSubtotal}); 
    } 

和呼叫看起来像这样

<app-bill [filler]="['Name','Rate', 'Qty', 'Discount', 'Subtotal']"></app-bill> 

,我需要通过所有这5个值赋给“填充符”()。

回答

1

创建该类型的一个对象,并传递的值,

<app-bill [filler]="item"></app-bill> 

其中由具有所有字段

Item.ts

class Item { 
    Name: string; 
    Rate: number; 
    Qty : number; 
    Discount : number; 
    SubTotal: number; 
} 

在类创建项目您的Catalog Component.ts

import { Item } from 'Item'; 

export class CheckOutPageComponent{ 
item : Item; 
ngOnInit() { 
     item.Name = 'test'; 
     ,,,,,,assign rest of values here 
} 
+0

我应该在哪里创建一个类,我如何使用它 –

+0

在您的应用程序 – Sajeetharan

+0

@KedarUdupa应该在父组件 – Sajeetharan