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 MoorePosted Jul 4, 2020, 3:56 PM
Maureen MoorePosted Jul 4, 2020, 9:51 AM
Maureen MoorePosted Jul 3, 2020, 7:11 PM