Reputation: 1721
I have a parent and child component. Child component has template variables and i want to read them into parent.
Parent:
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {Page} from "ui/page";
import {ChildComponent} from '/components/child/child.component'
@Component({
selector: "parent",
template: "<child [List]="List"></child>",
directives: [ChildComponent]
})
export class ParentComponent implements OnInit {
// list contains selectable items (<a> tag in HTML)
@ViewChildren("item")
itemsList: QueryList<ElementRef>;
}
child :
import {Component, OnInit, ViewChild, Input} from '@angular/core';
import {Observable} from 'rxjs/Observable';
@Component({
selector: "child",
templateUrl: "components/child/child.html",
})
export class ChildComponent implements OnInit {
@Input() list: array;
.....
}
the template : child.html
<li *ngFor="let item of list" style="cursor: default;">
<a (click)="handleClick()" #item > item </a>
</li>
It is possible to obtain the items list in parent ??
Upvotes: 0
Views: 397
Reputation: 2285
You can pass data to and from nested component.
If you want to pass data from child to parent, you can use event emitter.
Please see this article Passing data to and from a nested component in Angular 2
Upvotes: 1