简体   繁体   English

添加字体真棒图标

[英]Adding Font Awesome icons

I wanted to add the Font Awesome icons to use within my application that I develop following this MOOC but it generated an error that I didn't understand.我想添加 Font Awesome 图标以在我按照此 MOOC开发的应用程序中使用,但它生成了一个我不明白的错误。

First I used NPM to search for Font Awesome in the project by typing the following at the prompt:首先,我使用 NPM 在项目中通过在提示符下键入以下内容来搜索 Font Awesome:

npm install font-awesome@4.7.0 --save

Then, I added a new file called _variables.scss in the src folder and add the following:然后,我在 src 文件夹中添加了一个名为 _variables.scss 的新文件并添加以下内容:

$fa-font-path : '../node_modules/font-awesome/fonts';

Then, open the styles.scss file and update it as follows:然后,打开styles.scss文件并按如下方式更新它:

. . .

@import 'variables';
@import '../node_modules/font-awesome/scss/font-awesome';

. . .

But when I start the service with ng serve --open I get the following:但是当我使用ng serve --open启动服务时,我得到以下信息:

C:\\Users\\antoi\\Documents\\Programming\\Teaching\\Me\\FullStack\\Angular\\conFusion>ng serve --open 10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/ i 「wds」: webpack output is served from / i 「wds」: 404s will fallback to //index.html C:\\Users\\antoi\\Documents\\Programming\\Teaching\\Me\\FullStack\\Angular\\conFusion>ng serve --open 10% building 3/3 modules 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.

The code is in the MOOC but if you need the repository, tell me.代码在 MOOC 中,但如果您需要存储库,请告诉我。

Actualizacion实现

I did an ng update --all and I no longer have the errors.我做了一个ng update --all并且我不再有错误。 However in app.component.html when adding the components footer and header但是在app.component.html添加组件页脚和页眉时

<app-header></app-header>
<app-menu></app-menu>
<app-footer></app-footer>

I have no more rendering on the localhost.我在本地主机上没有更多的渲染。 But if I delete the header and footer, I have the rendering again.但是如果我删除页眉和页脚,我会再次渲染。 However, for the first case as for the other I have no error.但是,对于第一种情况和另一种情况,我没有错误。

You can try the angular-font-awesome package你可以试试angular-font-awesome

npm i angular-font-awesome --save

Now add the module inside app.module.ts:现在在 app.module.ts 中添加模块:

import {AngularFontAwesomeModule} from 'angular-font-awesome';

Then inside your imports array add it as well然后在您的导入数组中添加它

imports: [
    ..
    AngularFontAwesomeModule
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM