ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278k

How to pass data from component to another on angular 7 ?

May 10 2020 3:11 AM
How to pass data from component to another on angular 7 ?
 
I work on angular 7  i need when click button transfer data from current component to another component
 
displayreportservice.ts 
  1. GetSpByRevisionId(datarevision : any){  
  2.    return this.http.post<any>('http://localhost:61265/api/report',datarevision)  
  3.      
  4.  }  
 currentcomponent.html
  1. <td> <button (click)="getDataByRevision(rep[0])">Download</button> </td>  
 
 
currentcomponent.ts
  1. ReportData:any={};
  2. getDataByRevision(RevId : any)  
  3.   {  
  4.     console.log("REVEISIONID IS " + RevId);  
  5.     console.log(this.ReportData);  
  6.     this.ReportData.forEach(function(e) { e.revisionID=RevId });  
  7.     this._displayreport.GetSpByRevisionId(this.ReportData).subscribe(async data=>{  
  8. console.log(data)  
  9. await  this.exportJsonAsExcelFile(data ,'datarevision');  
  10.     });  
  11.    //console.log(this.reportdetailslist);  
  12.     
  13.   }  
 How to transfer data from component above to target component when click button :
targetcomponent.ts 
  1. export class ReportCategoryComponent implements OnInit {  
  2. //reportlist:report[];  
  3. datalis:string;  
  4. reportlist:any[];  
  5. subreportlist:any[];  
  6. searchData:any={};  
  7.   constructor(public http: HttpClient, private _router: Router, private _displayreport: DisplayreportService) { }  
  8.   
  9.   ngOnInit() {  
  10. //here i need to get data of getdatabyrevisionfunction
  11. //meaning i need to get result of 
  12. this.exportJsonAsExcelFile(data ,'datarevision'); here
  13. }
  14. }
 How to transfer data from current component.ts to target component.ts

Answers (1)