前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Angular Component 开发时属性和运行时属性的对照

Angular Component 开发时属性和运行时属性的对照

作者头像
Jerry Wang
发布2020-09-30 10:40:08
1.1K0
发布2020-09-30 10:40:08
举报

看个具体的例子:

代码语言:javascript
复制
@Component({
  selector: 'cx-carousel',
  template: `
    <ng-container *ngFor="let item$ of items">
      <ng-container
        *ngTemplateOutlet="template; context: { item: item$ | async }"
      ></ng-container>
    </ng-container>
  `,
})
class MockCarouselComponent {
  @Input() title: string;
  @Input() template: TemplateRef<any>;
  @Input() items: any[];
}

图中蓝色高亮的items和template属性需要消费端传入:

下图是在另一个Component UI里消费MockCarouselComponent:

中括号里的items, title和template就是MockCarouselComponent使用@Input()指定的三个属性,等号右边的items

, title

和carouseItem都是另一个Component本身的属性。

最后渲染出的html网页里,CarouselComponent这三个属性显示如下:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-09-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档