Angular中从子组件循环表格数据无法正确显示。
创始人
2024-10-31 01:30:33
0

这个问题的原因在于在子组件中循环的数据无法正确传递到父组件中的表格中。为了解决这个问题,需要增加一些额外的代码来确保数据正确传递和显示。

  1. 在父组件中添加一个属性来保存子组件中需要循环的数据:
// parent.component.ts
export class ParentComponent {
  childData: any[] = [];
}
  1. 在子组件中,将需要循环的数据通过@Input()装饰器传递到父组件中:
// child.component.ts
import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    
          ...
        
{{ item.name }} {{ item.age }}
` }) export class ChildComponent { @Input() data: any[] = []; }
  1. 在父组件的模板中,将子组件的数据通过@Input()装饰器传递给子组件:
// parent.component.html

  1. 在父组件中,将需要循环的数据赋值给新增的属性:
// parent.component.ts
export class ParentComponent implements OnInit {
  childData: any[] = [];

  ngOnInit(): void {
    this.childData = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 35 }
    ];
  }
}

这样,子组件中的数据就能正确地循环并显示在父组件的表格中了。

相关内容

热门资讯

透视开挂!哈糖大菠萝助手(透视... 透视开挂!哈糖大菠萝助手(透视)德普之星透视辅助软件下载,教程攻略(有挂教程)-哔哩哔哩1、很好的工...
wejoker透视方法!菠萝辅... wejoker透视方法!菠萝辅助器免费版的特点(透视)工具-一直普及有挂1、菠萝辅助器免费版的特点有...
透视推荐!aapoker怎么开... 透视推荐!aapoker怎么开辅助器(透视)wpk德州局透视,教程阶段(今日头条)-哔哩哔哩1、aa...
德州圈脚本!hhpoker可以... 德州圈脚本!hhpoker可以控制吗(透视)教程-一贯解迷是真的挂1、在hhpoker可以控制吗插件...
透视有挂!wepoker私局辅... 透视有挂!wepoker私局辅助(透视)wepoker有脚本吗,教程指南(有挂讲解)-哔哩哔哩1、下...
wepoker脚本!德州透视h... wepoker脚本!德州透视hhpoker(透视)器-切实解密真的有挂wepoker脚本!德州透视h...
pokemmo辅助工具!德普之... pokemmo辅助工具!德普之星透视辅助软件激活码(透视)挂-原来透视有挂一、德普之星透视辅助软件激...
透视有挂!wepoker买脚本... 透视有挂!wepoker买脚本靠谱吗(透视)约局吧开挂神器是真的吗,教程要领(有挂方略)-哔哩哔哩1...
sohoo辅助!hhpoker... sohoo辅助!hhpoker到底可以透视吗(透视)方法-本来推荐真的是有挂1、许多玩家不知道hhp...
透视辅助!pokemmo手机版... 透视辅助!pokemmo手机版修改器(透视)佛手大菠萝13道挂哪里,教程教材(有挂实锤)-哔哩哔哩佛...