如何在 Angular 12 中使用 IxJS

问题描述

我正在清理一个旧项目并将前端的 Angular 升级到 12,我从 IxJS 获得了一堆构建,这是一个已经存在一段时间的库:

./node_modules/ix/asynciterable/asynciterablex.mjs:31:10 - Error: Module parse failed: Unexpected token (31:10)
File was processed with these loaders:
* ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
You may need an additional loader to handle the result of these loaders.
|       let i = 0;
|
>       for await (const item of source) {
|         yield projection.call(thisArg,item,i++,signal);
|       }

即使在我刚刚使用 Angular CLI 生成的干净的暂存器项目中也会发生这种情况,我只是将其放入 app.component.ts 以确保它命中库:

import { Component } from '@angular/core';
import * as aix from 'ix/asynciterable';
import * as aixop from 'ix/asynciterable/operators';

async function* source() {
  yield 1;
  yield 2;
  yield 3;
}

async function title(): Promise<string> {
  const parts = [];
  for await (const y of aix
    .from(source())
    .pipe(aixop.map(async (x) => x * 2))) {
    parts.push(String(y));
  }
  return parts.join();
}

@Component({
  selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.scss'],})
export class AppComponent {
  title = 'ng-scratch';

  world!: Promise<string>;

  ngOnInit() {
    this.world = title();
  }
}

并在 app.component.html 中输出:

Hello,{{world | async}}

奇怪的是,它只报告库中的错误;如果我将 title() 函数更改为 just:

,它就会消失
async function title(): Promise<string> {
  const parts = [];
  for await (const y of source()) {
    parts.push(String(y));
  }
  return parts.join();
}

有什么办法可以解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...