1.子组件自定义属性接收父组件传递过来的参数

  1. //1.子组件自定义属性接收父组件传递过来的参数
  2. //app.component.html
  3. <app-MovieItem [title]="title"></app-MovieItem>

2.在子组件中使用@Input进行注册

  1. //2.在子组件中使用@Input进行注册
  2. //MovieItem.component.ts
  3. import { Component, OnInit,Input } from '@angular/core';
  4. export class MovieItemComponent implements OnInit {
  5. @Input() title!: String;
  6. //@Input() music!:any
  7. }

3.在子组件的模板中直接使用

  1. //3.在子组件的模板中直接使用
  2. //MovieItem.component.html
  3. <div class="item" *ngFor="let item of music">
  4. <img src="{{item.coverImgUrl}}" alt="" class="img">
  5. <p class="title">{{item.name}}</p>
  6. <div class="play">{{item.playCount}}</div>
  7. </div>