【发布时间】:2019-12-31 00:11:59
【问题描述】:
我想添加 Font Awesome 图标以在我按照 this MOOC 开发的应用程序中使用,但它产生了一个我不理解的错误。
首先我使用 NPM 在项目中搜索 Font Awesome,在提示符下输入以下内容:
npm install font-awesome@4.7.0 --save
然后,我在 src 文件夹中添加了一个名为 _variables.scss 的新文件,并添加以下内容:
$fa-font-path : '../node_modules/font-awesome/fonts';
然后,打开 styles.scss 文件并更新如下:
. . .
@import 'variables';
@import '../node_modules/font-awesome/scss/font-awesome';
. . .
但是当我使用ng serve --open 启动服务时,我得到以下信息:
C:\Users\antoi\Documents\Programming\Teaching\Me\FullStack\Angular\conFusion>ng serve --open 10% 建造 3/3 模块 0 activei 「wds」:项目在http://localhost:4200/webpack-dev-server/ 运行 i 「wds」:webpack 输出来自 / i 「wds」: 404s 将回退到 //index.html
chunk {main} main.js, main.js.map (main) 2.08 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 122 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.09 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 394 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 339 kB [initial] [rendered]
Date: 2019-08-26T10:11:22.403Z - Hash: 8fbb15623a903204f6d1 - Time: 11587ms
ERROR in node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts:62:22 - error TS2420: Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'.
Type 'MockMediaQueryList' is missing the following properties from type 'MediaQueryList': onchange, addEventListener, removeEventListener, dispatchEvent
62 export declare class MockMediaQueryList implements MediaQueryList {
~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts:79:27 - error TS2304: Cannot find name 'MediaQueryListListener'.
79 addListener(listener: MediaQueryListListener): void;
~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts:81:23 - error TS2304: Cannot find name 'MediaQueryListListener'.
81 removeListener(_: MediaQueryListListener): void;
~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts:11:22 - error TS2420: Class 'ServerMediaQueryList' incorrectly implements interface 'MediaQueryList'.
Type 'ServerMediaQueryList' is missing the following properties from type 'MediaQueryList': onchange, addEventListener, removeEventListener, dispatchEvent
11 export declare class ServerMediaQueryList implements MediaQueryList {
~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts:28:27 - error TS2304: Cannot find name 'MediaQueryListListener'.
28 addListener(listener: MediaQueryListListener): void;
~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts:30:23 - error TS2304: Cannot find name 'MediaQueryListListener'.
30 removeListener(_: MediaQueryListListener): void;
~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts:42:15 - error TS2416: Property '_registry' in type 'ServerMatchMedia' is not assignable to the same property in base type 'MatchMedia'.
Type 'Map<string, ServerMediaQueryList>' is not assignable to type 'Map<string, MediaQueryList>'.
Type 'ServerMediaQueryList' is missing the following properties from type 'MediaQueryList': onchange, addEventListener, removeEventListener, dispatchEvent
42 protected _registry: Map<string, ServerMediaQueryList>;
~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts:54:15 - error TS2416: Property '_buildMQL' in type 'ServerMatchMedia' is not assignable to the same property in base type 'MatchMedia'.
Type '(query: string) => ServerMediaQueryList' is not assignable to type '(query: string) => MediaQueryList'.
Type 'ServerMediaQueryList' is not assignable to type 'MediaQueryList'.
54 protected _buildMQL(query: string): ServerMediaQueryList;
~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/observable-media/observable-media.d.ts:11:14 - error TS2416: Property 'subscribe' in type 'ObservableMedia' is not assignable to the same property in base type 'Subscribable<MediaChange>'.
Type '(next?: (value: MediaChange) => void, error?: (error: any) => void, complete?: () => void) => Subscription' is not assignable to type '{ (observer?: PartialObserver<MediaChange>): Unsubscribable; (next: null, error: null, complete: () => void): Unsubscribable; (next: null, error: (error: any) => void, complete?: () => void): Unsubscribable; (next: (value: MediaChange) => void, error: null, complete: () => void): Unsubscribable; (next?: (value: Medi...'.
Types of parameters 'next' and 'observer' are incompatible.
Type 'PartialObserver<MediaChange>' is not assignable to type '(value: MediaChange) => void'.
Type 'NextObserver<MediaChange>' is not assignable to type '(value: MediaChange) => void'.
Type 'NextObserver<MediaChange>' provides no match for the signature '(value: MediaChange): void'.
11 abstract subscribe(next?: (value: MediaChange) => void, error?: (error: any) => void, complete?: () => void): Subscription;
~~~~~~~~~
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Failed to compile.
代码在 MOOC 中,但如果您需要存储库,请告诉我。
实现
我做了一个ng update --all,我不再有错误。但是在app.component.html 添加组件页脚和页眉时
<app-header></app-header>
<app-menu></app-menu>
<app-footer></app-footer>
我没有更多在 localhost 上的渲染。但是如果我删除页眉和页脚,我会再次进行渲染。但是,对于第一种情况,对于另一种情况,我没有错误。
【问题讨论】:
-
有官方的 Font Awesome 组件:github.com/FortAwesome/angular-fontawesome
标签: javascript angular font-awesome