Answers for "pass data from one component to another angular"

0

transfer data from one component to another angular

import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
      <button (click)="sendMessage()">Send Message</button>
  `,
  styleUrls: ['./child.component.css']
})
export class ChildComponent {

  message: string = "Hola Mundo!"

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

  constructor() { }

  sendMessage() {
    this.messageEvent.emit(this.message)
  }
}
Posted by: Guest on September-17-2020
1

share data between components angular

import { Component, Input } from '@angular/core';
//Child-Component
@Component({
  selector: 'app-child',
  template: `
      Say {{ message }}
  `,
  styleUrls: ['./child.component.css']
})
export class ChildComponent {

  @Input() childMessage: string;

  constructor() { }

}
======================================================================
import { Component } from '@angular/core'; 
//Parent-Component data transfer to Child-Component
@Component({
  selector: 'app-parent',
  template: `
    <app-child [childMessage]="parentMessage"></app-child>
  `,
  styleUrls: ['./parent.component.css']
})
export class ParentComponent{
  parentMessage = "message from parent"
  constructor() { }
}
Posted by: Guest on March-31-2020
0

transfer data from one component to another angular

import { Component } from '@angular/core';

@Component({
  selector: 'app-parent',
  template: `
    Message: {{message}}
    <app-child (messageEvent)="receiveMessage($event)"></app-child>
  `,
  styleUrls: ['./parent.component.css']
})
export class ParentComponent {

  constructor() { }

  message:string;

  receiveMessage($event) {
    this.message = $event
  }
}
Posted by: Guest on September-17-2020
0

pass data from one component to another angular

Data Transfer from one component to another — Angular 7
----
Parent to Child: via Input.
Child to Parent: via Output() and EventEmitter.
Child to Parent: via ViewChild.
Unrelated Components: via a Service.
Posted by: Guest on August-20-2021

Code answers related to "pass data from one component to another angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language