angular - 将枚举项传递给模板中的子组件
问题描述
我尝试将枚举项传递给子组件:
<app-enum-selection [itemIgnore]=DataStatus.Coming_Soon ></app-enum-selection>
但我得到这个错误:
error TS2339: Property 'DataStatus' does not exist on type 'ConstructorComponent'.
<app-enum-selection [itemIgnore]=DataStatus.Coming_Soon></app-enum-selection>
src/app/constructor/constructor.component.ts:29:16
templateUrl: './constructor.component.html',
Error occurs in the template of component ConstructorComponent.
知道为什么我会出错吗?以及如何将枚举项传递给子组件?
解决方案
试试这样:
父组件:
enum DataStatus{
Coming_Soon,
...
}
export class ParentComponent {
public dataStatus = DataStatus;
}
子组件:
export class ChildComponent {
@Input() public set itemIgnore(value: any) {
console.log(value);
};
}
父组件模板:
您app-enum-selection
在父组件(假设)中的子组件选择器(假设ConstructorComponent
)将如下所示:
<app-enum-selection [itemIgnore]=dataStatus.Coming_Soon ></app-enum-selection>
子组件模板:
<div>{{itemIgnore}}</div>
推荐阅读
- c# - ASP.NET MVC 4 一键为每个订单提交 2 个表单
- linux - 计算模式在文本文件中出现的次数
- oracle - 为什么我在将 R 连接到 Oracle 时收到服务请求错误
- python - 使用不同样式的颜色在绘图中可视化数组
- java - 无法在java中的背景图像上添加内容
- git - TeamCity stderr:致命:无法将分支切换到非提交
- javascript - 如何将文本与柏树中的重音进行比较?
- java - 如何使用 OAuth 对 MicroProfile REST 客户端调用进行身份验证?
- python - Beautifulsoup select 适用于 Jupyter 但不适用于 VS Code
- excel - For Each 的更有效替代方案