8-1创建组件

  1. ng g component components/MovieItem

8-2app.component.html

  1. <app-movie-item></app-movie-item>

8-3父子组件传值

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

  1. <app-movie-item [title]="title"></app-movie-item>

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

  1. import { Component, OnInit,Input } from '@angular/core';
  2. export class MovieItemComponent implements OnInit {
  3. @Input() title!: String;
  4. }

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

  1. <p>{{title}}</p>