import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';@Component({ selector: 'app-child', templateUrl: './child.component.html', styleUrls: ['./child.component.css']})export class ChildComponent implements OnInit, OnChanges { @Input() greeting: string; @Input() user: {}; message = 'hello'; constructor() { } ngOnInit() { } ngOnChanges(changes: SimpleChanges): void { console.log(JSON.stringify(changes, null, 2)); }}
子组件问候语{
{greeting}}用户{
{user.name}}
import { Component } from '@angular/core';@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})export class AppComponent { greeting = 'nihao'; user: { name: string } = { name: 'cys' };}