我如何包括弹性布局


9

我试图将flex-layout添加到有角度的应用程序中,但是当我尝试并使用它时,该应用程序会中断。我已经安装了

npm i @angular/flex-layout @angular/cdk

然后导入到app.module.ts中

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

import [ FlexLayoutModule ]

我也将打字稿升级到最新的

npm i typescript@latest

但是,当应用尝试编译时,我会遇到各种错误:

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.

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

谢谢.....


或可能是打字稿版本>
Prashant Pimpale

Answers:


7

尝试在依赖项中添加tslib

npm install --save tslib

编辑

如果您使用的是Angular v8,请使用v8进行弹性布局,因为v9需要Angular v9。


没变。与以前相同的错误。
cpeddie

3
有人已经提出TS1086错误的问题。抢夺它及其解决方案。答案是v9 requires Angular v9 and more importantly TypeScript v3.7. Please use the v8 release of Flex Layout.
Ratnadeep Bhattacharyya

就是这样 Flex布局的版本错误。
cpeddie

23

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


谢谢,它对我有用!
user3856842
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.