“@output () angular” Código de respuesta

Enviar evento al componente infantil 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

salida angular

content_copy
export class ItemOutputComponent {

  @Output() newItemEvent = new EventEmitter<string>();

  addNewItem(value: string) {
    this.newItemEvent.emit(value);
  }
}
simon caf

@output () angular

@Input() and @Output() give a child component a way to communicate 
with its parent component.

@Input() lets a parent component update data in the child component. 
@Output() lets the child send data to a parent component.

// Please click source link for more details
Tiny Coders

Respuestas similares a “@output () angular”

Preguntas similares a “@output () angular”

Más respuestas relacionadas con “@output () angular” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código