如何包含 flex-layout?

cpe*_*die 11 angular-flex-layout angular

我正在尝试将 flex-layout 添加到 angular 应用程序,但是当我这样做并尝试使用它时,应用程序会中断。我已经安装

npm i @angular/flex-layout @angular/cdk
Run Code Online (Sandbox Code Playgroud)

然后在 app.module.ts 中导入

import { FlexLayoutModule } from '@angular/flex-layout';

import [ FlexLayoutModule ]
Run Code Online (Sandbox Code Playgroud)

我还将打字稿升级到最新版本

npm i typescript@latest
Run Code Online (Sandbox Code Playgroud)

但是当应用程序尝试编译时,我收到各种错误:

ERROR in node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:24:19 - error TS1086: An accessor cannot be declared in an ambient context.

24     protected get parentElement(): HTMLElement | null;
                 ~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:26:19 - error TS1086: An accessor cannot be declared in an ambient context.

26     protected get nativeElement(): HTMLElement;
                 ~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:28:9 - error TS1086: An accessor cannot be declared in an ambient context.

28     get activatedValue(): string;
       ~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:29:9 - error TS1086: An accessor cannot be declared in an ambient context.

29     set activatedValue(value: string);
       ~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/breakpoints/break-point-registry.d.ts:20:9 - error TS1086: An accessor cannot be declared in an ambient context.

20     get overlappings(): BreakPoint[];
       ~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/breakpoints/break-point-registry.d.ts:24:9 - error TS1086: An accessor cannot be declared in an ambient context.
Run Code Online (Sandbox Code Playgroud)

而这样的例子不胜枚举。我的版本不匹配吗?

fil*_*lol 27

这是因为您使用的是 Angular 8,但该库需要 Angular 9。在您的 package.json 中使用此版本: "@angular/flex-layout": "^8.0.0-beta.27"


Rat*_*yya 9

尝试在依赖项中添加 tslib

npm install --save tslib
Run Code Online (Sandbox Code Playgroud)

编辑

如果您使用的是 Angular v8,则使用 v8 进行 flex-layout,因为 v9 需要 Angular v9。

  • 有人已经提出了 TS1086 错误的问题。[掠夺它及其解决方案](https://github.com/angular/flex-layout/issues/1181#issuecomment-579023713)。答案是“v9 需要 Angular v9,更重要的是 TypeScript v3.7”。请使用 Flex Layout v8 版本。` (3认同)