如何将对象从父模板传递给子组件

时间:2019-10-13 16:34:23

标签: angular

我有一个看起来像这样的界面

export interface IDropdownOption {
  guid: string;
  width: string;
  isRequired: false;
  fieldText: string;
  selectedItem: string;
}

在我的Child组件中,我定义了这样的Input @Input()compInfo:IDropdownOption; 然后在我的父模板中使用这样的客户端

<app-ig-dropdown
        compInfo.guid="820E04E0-8084-4D9C-A268-D8C0D21E74F6"
        compInfo.width="200px"
        formControlName="combo1"
        compInfo.fieldText="Social Media">
</app-ig-dropdown>

这样做总是会产生错误,即对象compInfo中定义的任何这些值的属性都未定义。甚至可以将Object用作@input,然后从父模板设置值? 我试图避免声明50个以上的输入,因为我在父级上可能有10个子组件,每个子组件都有5个参数。 如果不支持此操作,我还能如何使其更清洁?

1 个答案:

答案 0 :(得分:1)

最终,我能够像这样在父模板中分配值来解决该问题。

const dict = {
  ui: {
    btn: "Anzahl",
    changeLang: "SPRACHE ÄNDERN"
  },
  app: {
    title: "Hook-Beispiel"
  }
};

export { dict };
相关问题