Angular material : passing data from one component to another - TagMerge
2Angular material : passing data from one component to anotherAngular material : passing data from one component to another

Angular material : passing data from one component to another

Asked 1 years ago
1
2 answers

What you have done so far is correct, The only thing remaining is to get the Department name in your AddEditDepComponent.

So in your AddEditDepComponent, You can inject the data that you sent from ShowDepComponent into its constructor. You already sent your data using the dialog.open() method.

All you have to do get that data inAddEditDepComponent .ts :

 constructor(
     @Inject(MAT_DIALOG_DATA) public data: any,
 ){}

 ngOnInit(): void {
 console.log(this.data.DepartmentName);
 }

Source: link

0

child.component.ts
import { Component, Input } from '@angular/core';


@Component({
  selector: 'app-child',
  templateUrl: './childcomponent.html',
  styleUrls: ['./child.component.css']
})
export class ChildComponent {
  @Input() name: string;
}
child.component.html
<div>
   <h1>{{name}}</h1></div>
app.component.html
<div>
   <h1>Welcome to angular world</h1>
   <app-child name="Gowtham"></app-child></div>
app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  myname = 'Gowtham';}
app.component.html
<div>
   <h1>Welcome to angular world</h1>
   <app-child [name]="myname"></app-child></div>

Source: link

Recent Questions on angular

    Programming Languages