Component Interaction
This cookbook contains recipes for common component communication scenarios in which two or more components share information.
import { Component, OnInit, Inject, forwardRef } from '@angular/core';
`forwardRef`
import { AppComponent } from '/AppComponent.ts';
@Inject(forwardRef(() => AppComponent))
public _AppComponent: AppComponent)
Pass data from child to parent with input binding
child =>
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Output() filterObj: EventEmitter<Object> = new EventEmitter<Object>();
this.filterObj.emit(filterObj);
parent =>
<app-user (filterData)="filterData($event)"></app-user>
filterData(filterObject) {
console.log('res>>', filterObject);
}
Pass data from parent to child with input binding
child =>
- @Input() modelNmae: any;
- @Input('master') masterName: string;
- @Input()
set filter(modelId) {
this.getUserList(modelId)
}
- get filter() { return this.modelId}
parent =>
-
@Selector <app-user [filter]="filter"></app-user>
@Selector <app-user [filter]="filter"></app-user>
No comments:
Post a Comment