angular - 以角度迭代对象打字稿
问题描述
我正在使用 Angular Formly 在我的页面上创建动态内容。
我用这个模板创建了一个“部分”组件:
@Component({
selector: 'section',
template: `
<section *ngFor="let component of to">
<h1 *ngIf="component.type == 'h1'">{{component.label}}</h1>
<p *ngIf="component.type == 'text'">{{component.label}}</p>
<a *ngIf="component.type == 'button'" href="{{ component.goTo }}">{{ component.label }}</a>
</section>
`,
})
export class SectionComponent extends FieldType {}
在Formly的领域,我有一个例子可以测试:
{
type: 'section',
templateOptions: {
component1: {
type: 'h1',
label: 'Section title',
},
component2: {
type: 'text',
label: 'Inside section text',
},
component3: {
type: 'button',
label: 'Inside section button',
goTo : '/myeditor',
},
}
}
根据 Formly 文档,ngFor 中的“to”指的是 templateOptions。
但是,呈现此代码返回:
<section></section>
这意味着可能 ngFor 无法正确解析 templateOptions 上存在的组件。
PS:模板没有ngFor的其他组件(除了SectionComponent)可以正常工作并正确呈现。
解决方案
推荐阅读
- oracle - Oracle Apex - 保存更改后出现“您的会话已结束”消息
- python - 如何让我的输出打印行上升而不是水平打印?
- javascript - javascript字符串字符分配问题
- python - 使用python检查excel中一组超链接的活动和非活动状态
- python-3.x - 从 AWS 无服务器调用 GPG 方法
- amazon-web-services - 使用 IAM 角色权限防止用户在没有密钥对的情况下在 CLI 中启动 EC2 实例
- deep-learning - 在没有单独的 TRAIN/TEST 目录的情况下加载约会:Pytorch (ImageFolder)
- sql - 执行sql查询时出错,但独立执行选择时不会出错
- java - 同时运行多个实例并使用 java 中的 rest api 定期发送
- android-jetpack-compose - 没有片段的jetpack-compose应用程序中的依赖生命周期