Angular - Get parent component receive data after init@Directive v/s @Component in AngularAngular 2: getting RouteParams from parent componentAngular - Use pipes in services and componentsAngular dynamic tabs with user-click chosen components(Routable Component) Data tree with adjacent detail paneAngular - What is the meanings of module.id in component?Angular 2 click event causing entire component to re-initialize (losing state)Angular 4: How to use same component as both parent and child?How to select all the nodes on prime angular p-tree?Trying to receive file from mat-dialog angular in parent component
GFCI Outlet in Bathroom, Lights not working
Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?
Can an old DSLR be upgraded to match modern smartphone image quality
How to provide realism without making readers think grimdark
Is there a rule that prohibits us from using 2 possessives in a row?
Initialize an array of doubles at compile time
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
How can a single Member of the House block a Congressional bill?
You've spoiled/damaged the card
NTP rollover-safe design with ESP8266 (Curiosity)
Why don't B747s start takeoffs with full throttle?
What's the most polite way to tell a manager "shut up and let me work"?
Opposite of "Squeaky wheel gets the grease"
Could a guilty Boris Johnson be used to cancel Brexit?
How can Iron Man's suit withstand this?
Applicants clearly not having the skills they advertise
Unorthodox way of solving Einstein field equations
What is the right way to float a home lab?
Does Peach's float negate shorthop knockback multipliers?
When leasing/renting out an owned property, is there a standard ratio between monthly rent and the mortgage?
Accidentally cashed a check twice
Why is Colorado so different politically from nearby states?
Anyone teach web development? How do you assess it?
Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?
Angular - Get parent component receive data after init
@Directive v/s @Component in AngularAngular 2: getting RouteParams from parent componentAngular - Use pipes in services and componentsAngular dynamic tabs with user-click chosen components(Routable Component) Data tree with adjacent detail paneAngular - What is the meanings of module.id in component?Angular 2 click event causing entire component to re-initialize (losing state)Angular 4: How to use same component as both parent and child?How to select all the nodes on prime angular p-tree?Trying to receive file from mat-dialog angular in parent component
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have Angular front end which fetches data from Lumen backend:
ngAfterViewInit()
merge()
.pipe(
startWith(),
switchMap(() =>
this.isLoadingResults = true;
return this.exampleDatabase!.getRepoIssues(this.itemId);
),
map(data =>
this.isLoadingResults = false;
this.isRateLimitReached = false;
return data;
),
catchError(() =>
this.isLoadingResults = false;
this.isRateLimitReached = true;
return observableOf([]);
)
).subscribe(
data => this.applyDataChanges(data)
);
private applyDataChanges(data: any)
let tree = [];
for(let b of data.buildings)
let children = [];
for(let c of b.buildings)
children.push(new ChecklistNodeModel(c.name, false))
tree.push(new ChecklistNodeModel(b.group.name, false, children));
this.TREE_DATA = tree;
this.itemId > 0 ?
this.form = data as ControllingCompanyNewsModel :
this.form = new ControllingCompanyNewsModel(0,null,'','','', data.buildings);
Parent component has following property which then passes through @Input binding to child component:
<app-checklist-tree [treeData]="TREE_DATA"></app-checklist-tree>
and
@Input() treeData = [];
The question is for sone reason the child component has empty treeData
property. While parent component has property updated correctly.
Could anyone advice where I made a mistake?
Thank you!
Adding child component code
export class ChecklistTreeComponent implements AfterViewInit, OnChanges
@Input() treeData = [];
@Output() treeDataChange = new EventEmitter<ChecklistNodeModel[]>();
levels = new Map<ChecklistNodeModel, number>();
treeControl: FlatTreeControl<ChecklistNodeModel>;
treeFlattener: MatTreeFlattener<ChecklistNodeModel, ChecklistNodeModel>;
dataSource: MatTreeFlatDataSource<ChecklistNodeModel, ChecklistNodeModel>;
constructor(private changeDetectorRef: ChangeDetectorRef)
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl<ChecklistNodeModel>(
this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
// this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.dataSource.data = this.treeData;
getLevel = (node: ChecklistNodeModel): number => 0;
;
isExpandable = (node: ChecklistNodeModel): boolean =>
return node.children.value.length > 0;
;
getChildren = (node: ChecklistNodeModel) =>
return node.children;
;
transformer = (node: ChecklistNodeModel, level: number) =>
this.levels.set(node, level);
return node;
hasChildren = (index: number, node: ChecklistNodeModel) =>
return this.isExpandable(node);
/** The selection for checklist */
checklistSelection = new SelectionModel<ChecklistNodeModel>(true /* multiple */);
/** Whether all the descendants of the node are selected */
descendantsAllSelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return this.checklistSelection.isSelected(node);
const selected = this.checklistSelection.isSelected(node);
const allSelected = descendants.every(child => this.checklistSelection.isSelected(child));
if (!selected && allSelected)
this.checklistSelection.select(node);
this.changeDetectorRef.markForCheck();
return allSelected;
/** Whether part of the descendants are selected */
descendantsPartiallySelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return false;
const result = descendants.some(child => this.checklistSelection.isSelected(child));
return result && !this.descendantsAllSelected(node);
/** Toggle the selection. Select/deselect all the descendants node */
nodeSelectionToggle(node: ChecklistNodeModel): void
node.checked = !node.checked;
this.checklistSelection.toggle(node);
const descendants = this.treeControl.getDescendants(node);
if(this.checklistSelection.isSelected(node))
this.checklistSelection.select(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
else
this.checklistSelection.deselect(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
this.changeDetectorRef.markForCheck();
ngAfterViewInit(): void
this.dataSource.data = this.treeData;
ngOnChanges(changes: SimpleChanges): void
this.dataSource.data = changes.treeData.currentValue;
angular angular-material
|
show 6 more comments
I have Angular front end which fetches data from Lumen backend:
ngAfterViewInit()
merge()
.pipe(
startWith(),
switchMap(() =>
this.isLoadingResults = true;
return this.exampleDatabase!.getRepoIssues(this.itemId);
),
map(data =>
this.isLoadingResults = false;
this.isRateLimitReached = false;
return data;
),
catchError(() =>
this.isLoadingResults = false;
this.isRateLimitReached = true;
return observableOf([]);
)
).subscribe(
data => this.applyDataChanges(data)
);
private applyDataChanges(data: any)
let tree = [];
for(let b of data.buildings)
let children = [];
for(let c of b.buildings)
children.push(new ChecklistNodeModel(c.name, false))
tree.push(new ChecklistNodeModel(b.group.name, false, children));
this.TREE_DATA = tree;
this.itemId > 0 ?
this.form = data as ControllingCompanyNewsModel :
this.form = new ControllingCompanyNewsModel(0,null,'','','', data.buildings);
Parent component has following property which then passes through @Input binding to child component:
<app-checklist-tree [treeData]="TREE_DATA"></app-checklist-tree>
and
@Input() treeData = [];
The question is for sone reason the child component has empty treeData
property. While parent component has property updated correctly.
Could anyone advice where I made a mistake?
Thank you!
Adding child component code
export class ChecklistTreeComponent implements AfterViewInit, OnChanges
@Input() treeData = [];
@Output() treeDataChange = new EventEmitter<ChecklistNodeModel[]>();
levels = new Map<ChecklistNodeModel, number>();
treeControl: FlatTreeControl<ChecklistNodeModel>;
treeFlattener: MatTreeFlattener<ChecklistNodeModel, ChecklistNodeModel>;
dataSource: MatTreeFlatDataSource<ChecklistNodeModel, ChecklistNodeModel>;
constructor(private changeDetectorRef: ChangeDetectorRef)
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl<ChecklistNodeModel>(
this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
// this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.dataSource.data = this.treeData;
getLevel = (node: ChecklistNodeModel): number => 0;
;
isExpandable = (node: ChecklistNodeModel): boolean =>
return node.children.value.length > 0;
;
getChildren = (node: ChecklistNodeModel) =>
return node.children;
;
transformer = (node: ChecklistNodeModel, level: number) =>
this.levels.set(node, level);
return node;
hasChildren = (index: number, node: ChecklistNodeModel) =>
return this.isExpandable(node);
/** The selection for checklist */
checklistSelection = new SelectionModel<ChecklistNodeModel>(true /* multiple */);
/** Whether all the descendants of the node are selected */
descendantsAllSelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return this.checklistSelection.isSelected(node);
const selected = this.checklistSelection.isSelected(node);
const allSelected = descendants.every(child => this.checklistSelection.isSelected(child));
if (!selected && allSelected)
this.checklistSelection.select(node);
this.changeDetectorRef.markForCheck();
return allSelected;
/** Whether part of the descendants are selected */
descendantsPartiallySelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return false;
const result = descendants.some(child => this.checklistSelection.isSelected(child));
return result && !this.descendantsAllSelected(node);
/** Toggle the selection. Select/deselect all the descendants node */
nodeSelectionToggle(node: ChecklistNodeModel): void
node.checked = !node.checked;
this.checklistSelection.toggle(node);
const descendants = this.treeControl.getDescendants(node);
if(this.checklistSelection.isSelected(node))
this.checklistSelection.select(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
else
this.checklistSelection.deselect(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
this.changeDetectorRef.markForCheck();
ngAfterViewInit(): void
this.dataSource.data = this.treeData;
ngOnChanges(changes: SimpleChanges): void
this.dataSource.data = changes.treeData.currentValue;
angular angular-material
1
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57
|
show 6 more comments
I have Angular front end which fetches data from Lumen backend:
ngAfterViewInit()
merge()
.pipe(
startWith(),
switchMap(() =>
this.isLoadingResults = true;
return this.exampleDatabase!.getRepoIssues(this.itemId);
),
map(data =>
this.isLoadingResults = false;
this.isRateLimitReached = false;
return data;
),
catchError(() =>
this.isLoadingResults = false;
this.isRateLimitReached = true;
return observableOf([]);
)
).subscribe(
data => this.applyDataChanges(data)
);
private applyDataChanges(data: any)
let tree = [];
for(let b of data.buildings)
let children = [];
for(let c of b.buildings)
children.push(new ChecklistNodeModel(c.name, false))
tree.push(new ChecklistNodeModel(b.group.name, false, children));
this.TREE_DATA = tree;
this.itemId > 0 ?
this.form = data as ControllingCompanyNewsModel :
this.form = new ControllingCompanyNewsModel(0,null,'','','', data.buildings);
Parent component has following property which then passes through @Input binding to child component:
<app-checklist-tree [treeData]="TREE_DATA"></app-checklist-tree>
and
@Input() treeData = [];
The question is for sone reason the child component has empty treeData
property. While parent component has property updated correctly.
Could anyone advice where I made a mistake?
Thank you!
Adding child component code
export class ChecklistTreeComponent implements AfterViewInit, OnChanges
@Input() treeData = [];
@Output() treeDataChange = new EventEmitter<ChecklistNodeModel[]>();
levels = new Map<ChecklistNodeModel, number>();
treeControl: FlatTreeControl<ChecklistNodeModel>;
treeFlattener: MatTreeFlattener<ChecklistNodeModel, ChecklistNodeModel>;
dataSource: MatTreeFlatDataSource<ChecklistNodeModel, ChecklistNodeModel>;
constructor(private changeDetectorRef: ChangeDetectorRef)
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl<ChecklistNodeModel>(
this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
// this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.dataSource.data = this.treeData;
getLevel = (node: ChecklistNodeModel): number => 0;
;
isExpandable = (node: ChecklistNodeModel): boolean =>
return node.children.value.length > 0;
;
getChildren = (node: ChecklistNodeModel) =>
return node.children;
;
transformer = (node: ChecklistNodeModel, level: number) =>
this.levels.set(node, level);
return node;
hasChildren = (index: number, node: ChecklistNodeModel) =>
return this.isExpandable(node);
/** The selection for checklist */
checklistSelection = new SelectionModel<ChecklistNodeModel>(true /* multiple */);
/** Whether all the descendants of the node are selected */
descendantsAllSelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return this.checklistSelection.isSelected(node);
const selected = this.checklistSelection.isSelected(node);
const allSelected = descendants.every(child => this.checklistSelection.isSelected(child));
if (!selected && allSelected)
this.checklistSelection.select(node);
this.changeDetectorRef.markForCheck();
return allSelected;
/** Whether part of the descendants are selected */
descendantsPartiallySelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return false;
const result = descendants.some(child => this.checklistSelection.isSelected(child));
return result && !this.descendantsAllSelected(node);
/** Toggle the selection. Select/deselect all the descendants node */
nodeSelectionToggle(node: ChecklistNodeModel): void
node.checked = !node.checked;
this.checklistSelection.toggle(node);
const descendants = this.treeControl.getDescendants(node);
if(this.checklistSelection.isSelected(node))
this.checklistSelection.select(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
else
this.checklistSelection.deselect(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
this.changeDetectorRef.markForCheck();
ngAfterViewInit(): void
this.dataSource.data = this.treeData;
ngOnChanges(changes: SimpleChanges): void
this.dataSource.data = changes.treeData.currentValue;
angular angular-material
I have Angular front end which fetches data from Lumen backend:
ngAfterViewInit()
merge()
.pipe(
startWith(),
switchMap(() =>
this.isLoadingResults = true;
return this.exampleDatabase!.getRepoIssues(this.itemId);
),
map(data =>
this.isLoadingResults = false;
this.isRateLimitReached = false;
return data;
),
catchError(() =>
this.isLoadingResults = false;
this.isRateLimitReached = true;
return observableOf([]);
)
).subscribe(
data => this.applyDataChanges(data)
);
private applyDataChanges(data: any)
let tree = [];
for(let b of data.buildings)
let children = [];
for(let c of b.buildings)
children.push(new ChecklistNodeModel(c.name, false))
tree.push(new ChecklistNodeModel(b.group.name, false, children));
this.TREE_DATA = tree;
this.itemId > 0 ?
this.form = data as ControllingCompanyNewsModel :
this.form = new ControllingCompanyNewsModel(0,null,'','','', data.buildings);
Parent component has following property which then passes through @Input binding to child component:
<app-checklist-tree [treeData]="TREE_DATA"></app-checklist-tree>
and
@Input() treeData = [];
The question is for sone reason the child component has empty treeData
property. While parent component has property updated correctly.
Could anyone advice where I made a mistake?
Thank you!
Adding child component code
export class ChecklistTreeComponent implements AfterViewInit, OnChanges
@Input() treeData = [];
@Output() treeDataChange = new EventEmitter<ChecklistNodeModel[]>();
levels = new Map<ChecklistNodeModel, number>();
treeControl: FlatTreeControl<ChecklistNodeModel>;
treeFlattener: MatTreeFlattener<ChecklistNodeModel, ChecklistNodeModel>;
dataSource: MatTreeFlatDataSource<ChecklistNodeModel, ChecklistNodeModel>;
constructor(private changeDetectorRef: ChangeDetectorRef)
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl<ChecklistNodeModel>(
this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
// this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.dataSource.data = this.treeData;
getLevel = (node: ChecklistNodeModel): number => 0;
;
isExpandable = (node: ChecklistNodeModel): boolean =>
return node.children.value.length > 0;
;
getChildren = (node: ChecklistNodeModel) =>
return node.children;
;
transformer = (node: ChecklistNodeModel, level: number) =>
this.levels.set(node, level);
return node;
hasChildren = (index: number, node: ChecklistNodeModel) =>
return this.isExpandable(node);
/** The selection for checklist */
checklistSelection = new SelectionModel<ChecklistNodeModel>(true /* multiple */);
/** Whether all the descendants of the node are selected */
descendantsAllSelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return this.checklistSelection.isSelected(node);
const selected = this.checklistSelection.isSelected(node);
const allSelected = descendants.every(child => this.checklistSelection.isSelected(child));
if (!selected && allSelected)
this.checklistSelection.select(node);
this.changeDetectorRef.markForCheck();
return allSelected;
/** Whether part of the descendants are selected */
descendantsPartiallySelected(node: ChecklistNodeModel): boolean
const descendants = this.treeControl.getDescendants(node);
if (!descendants.length)
return false;
const result = descendants.some(child => this.checklistSelection.isSelected(child));
return result && !this.descendantsAllSelected(node);
/** Toggle the selection. Select/deselect all the descendants node */
nodeSelectionToggle(node: ChecklistNodeModel): void
node.checked = !node.checked;
this.checklistSelection.toggle(node);
const descendants = this.treeControl.getDescendants(node);
if(this.checklistSelection.isSelected(node))
this.checklistSelection.select(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
else
this.checklistSelection.deselect(...descendants, node);
for(let descendant of descendants)
this.nodeSelectionToggle(descendant);
this.changeDetectorRef.markForCheck();
ngAfterViewInit(): void
this.dataSource.data = this.treeData;
ngOnChanges(changes: SimpleChanges): void
this.dataSource.data = changes.treeData.currentValue;
angular angular-material
angular angular-material
edited Mar 24 at 13:46
Vadorequest
5,7721064138
5,7721064138
asked Mar 24 at 12:29
Aleksandr PopovAleksandr Popov
12611
12611
1
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57
|
show 6 more comments
1
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57
1
1
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57
|
show 6 more comments
1 Answer
1
active
oldest
votes
Implement this in the parent component
//import CheckListTreeComponent
//Import viewChild from angular core
export class ParentClass
@ViewChild(ChecklistTreeComponent)
private tree : ChecklistTreeComponent;
constructor()
//
At the point you are sure that the parent component has received it's value
this.tree.update(this.TREE_DATA)
In the child component
update(value)
this.treeData = value;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323808%2fangular-get-parent-component-receive-data-after-init%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Implement this in the parent component
//import CheckListTreeComponent
//Import viewChild from angular core
export class ParentClass
@ViewChild(ChecklistTreeComponent)
private tree : ChecklistTreeComponent;
constructor()
//
At the point you are sure that the parent component has received it's value
this.tree.update(this.TREE_DATA)
In the child component
update(value)
this.treeData = value;
add a comment |
Implement this in the parent component
//import CheckListTreeComponent
//Import viewChild from angular core
export class ParentClass
@ViewChild(ChecklistTreeComponent)
private tree : ChecklistTreeComponent;
constructor()
//
At the point you are sure that the parent component has received it's value
this.tree.update(this.TREE_DATA)
In the child component
update(value)
this.treeData = value;
add a comment |
Implement this in the parent component
//import CheckListTreeComponent
//Import viewChild from angular core
export class ParentClass
@ViewChild(ChecklistTreeComponent)
private tree : ChecklistTreeComponent;
constructor()
//
At the point you are sure that the parent component has received it's value
this.tree.update(this.TREE_DATA)
In the child component
update(value)
this.treeData = value;
Implement this in the parent component
//import CheckListTreeComponent
//Import viewChild from angular core
export class ParentClass
@ViewChild(ChecklistTreeComponent)
private tree : ChecklistTreeComponent;
constructor()
//
At the point you are sure that the parent component has received it's value
this.tree.update(this.TREE_DATA)
In the child component
update(value)
this.treeData = value;
answered Mar 24 at 13:44
Ranika NisalRanika Nisal
32829
32829
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323808%2fangular-get-parent-component-receive-data-after-init%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you add the code of the child component ?
– Ranika Nisal
Mar 24 at 12:42
@RanikaNisal yes. please check
– Aleksandr Popov
Mar 24 at 12:44
So two questions: (1) Is the code that sets TREE_DATA in the parent being reached? (2) Have you tried putting ‘ngOnChanges(changes) console.log(changes) ’ or something similar in the child?
– Ethan Melamed
Mar 24 at 12:51
Do you get a simpleChanges object when you run the web app?
– Ranika Nisal
Mar 24 at 12:55
@EthanMelamed thanks for your responce. (1) yes it does updates TREE_DATA in parent as far as I can see from Augury. (2) nothing being outputed into logs
– Aleksandr Popov
Mar 24 at 12:57