TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maureen Moore
NA
206
0
Pass a variable from child to parent component
Jul 3 2020 7:05 PM
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:
<h1> From Child - {{ messageFromChild }} </h1>
I don't get any errors but {{ messageFromChild }} is blank.
Reply
Answers (
3
)
How to Find and replace both open and close tag with new tags
How to handle changes on files on git source control before Pull last