我启动了一个NG2应用程序,想要添加更棒的字体。我npm安装它的方式是: npm install --save font-awawingangular2- font-awesome。我在systemjs.config.js中添加到项目中:
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'angular2-fontawesome': 'node_modules/angular2-fontawesome'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular2-fontawesome': { defaultExtension: 'js' }
}我在app.module.ts中添加了:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { CorporateComponent } from './corporate/corporate.component';
import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome'
@NgModule({
imports: [ BrowserModule , Angular2FontawesomeModule],
declarations: [ AppComponent, CorporateComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }现在我尝试在我的组件中使用它:我在html模板中添加:
<i class="fa fa-industry" aria-hidden="true"></i>但不知何故我看不出来。我遵循了npm的手册:https://www.npmjs.com/package/angular2-fontawesome
还有什么是我可能忘记的吗?
感谢您的回复!
发布于 2017-02-08 15:17:41
如果你想在你的应用中使用css样式,只需要把FontAwesome链接到你的index.html,你不需要angular2-font-awesome
index.html
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">如果您使用angular2-font-awesome
<i fa [name]="industry"></i>
<fa [name]="industry"></fa>我觉得用cdn更好。
发布于 2017-02-08 15:26:17
不需要做太多的工作,只需要包括标记。
<div>
<h2>Hello {{name}}</h2>
<i class="fa fa-home"></i>
</div>我的index.html包含对上述脚本URL的脚本引用。

通过获取您的脚本代码。你会收到一封来自font-awesome的邮件,如下所示

发布于 2017-11-09 03:00:04
我认为您需要像这样将它添加到您的.angular-cli.json部分:
您可以在您的node_modules中使用不同的名称。尝试向下查看node_modules中的列表,看看它是在什么名称下安装的。我注意到的另一件事是npm install --save font-awesome angular-font-awesome
`"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/npm-font-open-sans/open-sans.styl"
],https://stackoverflow.com/questions/42106818
复制相似问题