0

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 ??

1 Answer 1

1

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

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.