1

my parent component html:

<app-calendar-component [view]="calView" [callback]="calendarOptions" ></app-calendar-component>
<app-weekdetails-component *ngIf="test"></app-weekdetails-component>

my parent component ts:

public test:boolean=false;

appCalendarComponent:

ngOnInit(){
Calling services here and using data, after this process I need to set 
my variable test to be true which is defined in parent component.
}

So I need to set variable test to be true when 1st child(appCalendarComponent) is initialized.

1
  • 1
    usuly, i use some output inside my child component to interact into the parent variable. But will your variable be used elsewhere? if so you may use some service to define those variables with maybe some obsever + subject tricks to get it automaticaly inside your parent component Commented Nov 20, 2017 at 15:35

1 Answer 1

5

You should use output way to comunicate with the parent component.

On the child:

import { Component, Output, EventEmitter } from '@angular/core';

@Output() componentInit = new EventEmitter<>();

ngOnInit(){
Calling services here and using data, after this process I need to set 
my variable test to be true which is defined in parent component.

//After init
 this.componentInit.emit();
}

On the parent:

HTML:

<app-calendar-component 
                  (componentInit)="componentInitialize()" 
                  [view]="calView" 
                  [callback]="calendarOptions">
</app-calendar-component>

TypeScript:

componentInitialize():void{
 this.test = true;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.