Answer the question
In order to leave comments, you need to log in
How to implement data passing between two components in Angular 7?
There are two neighboring components
<b2b-acquiring *ngIf="resultSearchByNumber" [inputData]="resultSearchByNumber"></b2b-acquiring>
<b2b-restart-business-process></b2b-restart-business-process>
b2b-acquiring
has a method that sends a request to the server and here is the response that comes up, I need to pass it to the b2b-restart-business-process
getPayInfoExtended(obj: any) {
this.resultSearchByNumber = null;
this.resultSearchByNumber = obj;
this.resultGetPayInfoExtended = null;
return this.http.post(`${this.baseUrl}`+'getpayinfoextended?', this.resultSearchByNumber).subscribe(res => {
this.resultGetPayInfoExtended = res;
},
error => {
console.log(error)
})
}
@Output
it but I don't understand how it works. Explain on your fingers please @Output
b2b-acquiring
@Output() payInfo = new EventEmitter();
sendDateToParent() {
this.payInfo.emit(this.resultGetPayInfoExtended);
}
payInfoTest(evnt) {
this.payInfoData = null;
this.payInfoData = evnt;
console.log(this.payInfoData)
}
<b2b-acquiring *ngIf="resultSearchByNumber" [inputData]="resultSearchByNumber" (payInfo)="payInfoTest($event)"></b2b-acquiring>
b2b-restart-business-process
? @Input
@Input() inputData2;
<b2b-restart-business-process [inputData2]="payInfoData"></b2b-restart-business-process>
{{ inputData2 | json }}
Answer the question
In order to leave comments, you need to log in
It's not how it's done at all.
The service should deal with this, the components are representation classes, there should not be work with data.
The service has a subject with data and a data request method that returns an observable, throwing data into the subject along the way.
The first component pulls the method and subscribes to it, thereby launching it for execution.
The second component is subscribed to the subject, best of all through the async pipe.
@Output() in the first component, if you want to use it, it should not show data, but an event on which the parent component will request data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question