找不到其他支持对象

时间:2018-11-30 10:05:52

标签: angular typescript angular6

我想使用RxJs中的switchMap(...)顺序执行休息请求。

对象:

export class Transaction {
  constructor(
    public id: string,
    public unique_id: string,
    public name: string,
    public status: string,
    public type: string,
    public created_at: Date
  ) {}
}

组件:

@Component({
  selector: 'app-transaction-details',
  templateUrl: './transaction-details.component.html',
  styleUrls: ['./transaction-details.component.scss']
})
export class TransactionDetailsComponent implements OnInit {

  processingLogs: ProcessingLogs = new ProcessingLogs(null, null, null, null, null);
  transaction: Transaction;

  constructor(private transactionService: TransactionService,
              private processingLogsService: ProcessingLogsService,
              private route: ActivatedRoute) { }

  ngOnInit() {
    this.route.params.pipe(
      flatMap(params => {
        if(params['id']) {
          return this.transactionService.get(params['id']);
        } else {
          return of(null);
        }
      })
    ).subscribe(value => {
      if(value != null) {
        this.transaction = value;
      }
    });

    this.route.params.pipe(
      flatMap(params => {
        if (transaction.unique_id) {
          return this.processingLogsService.getProcessingLogsList(transaction.unique_id);
        } else {
          return of(null);
        }
      })
    ).subscribe(value => {
      if (value != null) {
        this.processingLogs = value;
      }
    });
  }
}

我尝试过:

this.route.params.pipe(
  map(params=>params['id']),
  switchMap(idParameter=> this.processingLogsService.getProcessingLogsList(idParameter))
).subscribe(logList=>
  value => this.processingLogsService.getProcessingLogsList(value.unique_id)
);

首先,我想使用http链接中的transactionService.get(params['id'])加载id。 第二,在加载对象Transaction时,我想使用从第一个请求加载的getProcessingLogsList(transaction.unique_id)来加载unique_id。我收到错误消息:

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
    at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3152)
    at checkAndUpdateDirectiveInline (core.js:9246)

页面数据为空。我该如何解决这个问题?

0 个答案:

没有答案