我使用npm将fontawesome 5(免费)安装到本地项目中,但是当我尝试在代码中使用图标时,它们不会出现在我的视图中。
我使用npm安装了fontawesome npm install --save-dev @ fortawesome / fontawesome-free
然后在fontawesome.js文件中,导入了适当的fontawesome导入,包括要使用的特定图标。我在html中编码了i标签,然后运行npm run watch来编译我的scss和js代码。
在fontawesome.js中
import { Subscription, combineLatest } from 'rxjs';
sub: Subscription;
myData: any;
ngOnInit() {
this.sub = combineLatest(
this.brandService.getJsonBrands,
this.productService.getJsonProducts,
this.categoryService.getJsonCategories
).subscribe(([brands, products, categories]) => {
this.myData = {brands, products, categories};
console.log('this.myData', this.myData);
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
在show.blade.php
import { fas } from '@fortawesome/fontawesome';
import { faCaretUp } from '@fortawesome/fontawesome';
import { faCaretDown } from '@fortawesome/fontawesome';
import { faStar } from '@fortawesome/fontawesome';
import { faCheck } from '@fortawesome/fontawesome';
library.add(fas, faCaretUp, faCaretDown, faStar, faCheck);
// Kicks off the process of finding <i> tags and replacing with <svg>
dom.watch()
在package.json中(最新版本的fontawesome)
<i class="fas fa-caret-up"></i>
<i class="fas fa-caret-down"></i>
<i class="fas fa-star"></i>
我希望这些图标出现在我的视图中文本旁边,但是这些图标不会出现。