简体   繁体   English

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

[英]How do I pass multiple parameters to an @Input decorator function in Angular 4

My Input decorator looks like this 我的输入装饰器看起来像这样

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

and the call looks like this 通话看起来像这样

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

and I need to pass all those 5 values to the "filler()". 我需要将所有这5个值传递给“ filler()”。

Create a object of that type and pass the values, 创建该类型的对象并传递值,

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

where item is created from class which has all the fields 从具有所有字段的类创建项目的位置

Item.ts 项目

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

In your Catalog Component.ts Catalog Component.ts

import { Item } from 'Item';

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM