1-1 父组件给子组件传参

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

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

  1. import { Component, OnInit ,Input} from '@angular/core';
  2. export class MovieComponent implements OnInit {
  3. constructor() { }
  4. @Input() title!:String;#// ! 表示必须传递
  5. ngOnInit() {
  6. }
  7. }

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

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