Angular父组件和多个子组件内容投影
创始人
2024-10-25 01:30:49
0

在Angular中,可以使用内容投影(Content Projection)来实现父组件向其子组件传递内容。

下面是一个示例,展示了父组件和两个子组件之间的内容投影:

  1. 父组件模板(parent.component.html):

父组件内容

  1. 子组件1模板(child1.component.html):

子组件1内容

  1. 子组件2模板(child2.component.html):

子组件2内容

  1. 父组件(ParentComponent):
import { Component } from '@angular/core';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css']
})
export class ParentComponent { }
  1. 子组件1(Child1Component):
import { Component } from '@angular/core';

@Component({
  selector: 'app-child1',
  templateUrl: './child1.component.html',
  styleUrls: ['./child1.component.css']
})
export class Child1Component { }
  1. 子组件2(Child2Component):
import { Component } from '@angular/core';

@Component({
  selector: 'app-child2',
  templateUrl: './child2.component.html',
  styleUrls: ['./child2.component.css']
})
export class Child2Component { }

现在,当在父组件中使用子组件时,可以通过标签将内容传递给子组件:


  
    

子组件1的内容

子组件2的内容

在上述示例中,父组件的内容将显示在标签中,子组件1和子组件2的内容将通过内容投影插入到对应的标签中。

相关内容

热门资讯

辅助透视!智星菠萝可以辅助吗(... 辅助透视!智星菠萝可以辅助吗(透视)九九联盟后台可以操作吗(本来存在有辅助工具)-哔哩哔哩1、首先打...
透视游戏!扑克之星辅助(透视)... 透视游戏!扑克之星辅助(透视)微信十三张脚本(一直是有辅助修改器)-哔哩哔哩微信十三张脚本辅助器是一...
据目击者称!wpk私人辅助(透... 据目击者称!wpk私人辅助(透视)闲逸游戏游透视吗(真是是有辅助安装)-哔哩哔哩进入游戏-大厅左侧-...
透视透视!wepokerplu... 透视透视!wepokerplus脚本(透视)中至九江都昌讨赏插件(确实是有辅助工具)-哔哩哔哩1、每...
此事备受玩家关注!aa pok... 此事备受玩家关注!aa poker透视软件(透视)创思维辅助软件(竟然真的是有辅助app)-哔哩哔哩...
此事引发网友热议!wepoke... 此事引发网友热议!wepoker分析(透视)皮皮衡阳字牌黑科技视频(竟然真的是有辅助神器)-哔哩哔哩...
在玩家背景下!hhpkoer辅... 在玩家背景下!hhpkoer辅助器(透视)衢州都莱辅助器是真的假的(果然是真的辅助下载)-哔哩哔哩1...
突发!德普之星私人局辅助器(透... 突发!德普之星私人局辅助器(透视)欢乐达人暗堡链接脚本(真是有辅助插件)-哔哩哔哩1、首先打开欢乐达...
据玩家消息!wepoker有辅... 据玩家消息!wepoker有辅助插件吗(透视)江西中指黑科技辅助软件(一贯真的有辅助神器)-哔哩哔哩...
刚刚!hhpkoer辅助器(透... 刚刚!hhpkoer辅助器(透视)博弈麻友圈辅助(确实有辅助下载)-哔哩哔哩1、超多福利:超高返利,...