Answer the question
In order to leave comments, you need to log in
How to get data from service in child component after change by parent?
Hello.
I apologize for the somewhat confused description and terminology, until I fully understand the specifics of development on Angular 2.
I have the following component hierarchy:
MemberComponent -> DesktopComponent (router-outlet) -> PaymentHistoryComponent
Service: AccountService.
export class AccountService {
public accountSource = new Subject();
public account: Observable<any> = this.accountSource.asObservable();
public getAccount() {
return this.account;
}
public setAccount(account) {
this.accountSource.next(account);
}
...
public changeAccount() {
this.accountService.setAccount(this.account);
}
export class PaymentHistoryComponent implements OnInit {
public history;
public constructor(
public paymentService: PaymentSercice,
public accountService: AccountService,
public router: Router
) {
}
public ngOnInit() {
this.accountService.getAccount().subscribe((account) => {
this.paymentService.getHistory(account.value).then(history => this.history = history);
});
}
}
this.accountService.getAccount().subscribe(...)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question