如何将多个参数传递给Angular 4中的@Input装饰器函数

时间:2017-10-06 10:04:07

标签: angular

我的输入装饰器看起来像这样

array_of_hit_uuids

并且通话看起来像这样

    @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});
  }

我需要将所有这5个值传递给“filler()”。

1 个答案:

答案 0 :(得分:1)

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

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

其中item是从包含所有字段的类创建的

<强> 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
 }
相关问题