“Lulus Data dari Parent to Child Component Angular 8” Kode Jawaban

Kirim Acara ke Komponen Anak Angular

Parent-Component

eventsSubject: Subject<void> = new Subject<void>();

emitEventToChild() {
  this.eventsSubject.next();
}


Parent-HTML

<child [events]="eventsSubject.asObservable()"> </child>


Child-Component

private eventsSubscription: Subscription;

@Input() events: Observable<void>;

ngOnInit(){
  this.eventsSubscription = this.events.subscribe(() => doSomething());
}

ngOnDestroy() {
  this.eventsSubscription.unsubscribe();
}
Coding is simple XD

data lewat sudut ke komponen anak

Parent component:
<app-child-component [item]="data"></app-child-component>

Child component.ts
import { Component, Input } from '@angular/core'; // First, import Input
export class ItemDetailComponent {
  @Input() item = ''; // decorate the property with @Input()
}
MitchAloha

Perent ke Data Anak Lulus Dalam Angular

//app.html:
<h1>this is perent component</h1>
<app-child [items]="employee"></app-child>
//app.component.ts:
 employee = {
    id: 1,
    name: 'chintan',
    address: 'junagadh',
  };
//child.component.ts:
@Input() items: any;
//child.html:
<h2>{{ items.id }}</h2>
<h2>{{ items.name }}</h2>
<h2>{{ items.address }}</h2>
30_Savaliya Denish

Lulus Data dari Parent to Child Component Angular 8

Parent-Component

eventsSubject: Subject<void> = new Subject<void>();

emitEventToChild() {
  this.eventsSubject.next();
}
Parent-HTML
<child [events]="eventsSubject.asObservable()"> </child>
Child-Component

private eventsSubscription: Subscription;

@Input() events: Observable<void>;

ngOnInit(){
  this.eventsSubscription = this.events.subscribe(() => doSomething());
}

ngOnDestroy() {
  this.eventsSubscription.unsubscribe();
}
Cautious Centipede

Jawaban yang mirip dengan “Lulus Data dari Parent to Child Component Angular 8”

Pertanyaan yang mirip dengan “Lulus Data dari Parent to Child Component Angular 8”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya