So I am trying to get a value from my child component to print in my parent component and I tried the following:
In my child component ts:
- export class ChildComponent {
- message: string = 'Hello!!!';
- }
In my parent component ts:
- import { Component, ViewChild, AfterViewInit} from '@angular/core';
- import { ChildComponent } from '../child/child.component'
- export class ShoppingCartComponent implements ControlValueAccessor, AfterViewInit {
- messageFromChild : string;
- @ViewChild(ChildComponent) myChild;
- ngAfterViewInit() {
- this.messageFromChild = this.myChild.message;
- }
- }
In my parent component html:
From Child - {{ messageFromChild }}
I don't get any errors but {{ messageFromChild }} is blank.

Maureen MooreRank #5,080 · 312 reputationPosted Jul 3, 2020, 3:11 PM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Jul 4, 2020, 5:51 AM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Jul 4, 2020, 11:56 AM EDT