在其他订阅方法中调用可观察到的异步管道

时间:2019-03-29 04:19:17

标签: angular6 observable

我在ngOnInit上调用了两次可观察到的异步管道,第二次在其他订阅内部调用了异步管道。因此,问题在于异步管道可观察的调用仅在第二次之后才被​​第一次调用。

通过异步管道可观察到

HTML代码:

<ul class="dropdown-menu">
      <li *ngFor="let item of accountTypes | async">
        <a href="javascript:void(0)">{{item.Code}}</a>
      </li>
</ul>

角度代码:

accountTypes: Observable<Array<AgencyInfo>>;

ngOnInit() {
 // first call -- working fine
 this.accountTypes = this.accountsService.getAgency(-1);
}

// call method on button click
getGBACSalesPersonCode() {
this.authenticationService.getGBACSalesPersonCodes().subscribe((res: 
any[]) => {
    // second call -- not calling api(error)
    this.accountTypes = this.accountsService.getAgency(5);
 });
}

第二个调用应调用API。

0 个答案:

没有答案