I'm using angular 7.0.1 and angular material 7.0.2, I want to add the font awesome 5.4.2 icons and I'm trying to follow the steps on fontawesome web but I can't get the font awesome icon font.
first:
npm install --save-dev #fortawesome/fontawesome-free
then in styles.scss add:
#import '~#fortawesome/fontawesome-free/scss/fontawesome.scss';
and in _variables.scss add:
$fa-font-path: '~#fortawesome/fontawesome-free/webfonts';
now in app.component.ts add:
import { MatIconRegistry } from "#angular/material";
[...]
constructor(
public matIconRegistry: MatIconRegistry,
) {
matIconRegistry.registerFontClassAlias ('fas'); // tried with 'fas' and with 'fa'
}
and finally I'm suposed to print the font awesome icons with:
<mat-icon mat-list-icon fontIcon="fas github"></mat-icon> // tryed also with 'fas-github', 'fasGithub', 'github', 'fa-github', 'fa github' and 'faGithub'
But the font awesome icon font is never printed. I'm missing something important and obvious but right now I'm not seeing it.
This is what I've done and it works for me:
In my styles.scss I have
#import "~#fortawesome/fontawesome-free/css/all.css";
Then I have
<mat-icon fontSet="fa" fontIcon="fa-clipboard-check"></mat-icon>
With scss it didnt work for me either.
I followed below simple steps,
it works for me to install font awesome 5.6.3 (free version) in my Angular 7 project.
run below command to install font-awesome latest version.
npm install --save-dev #fortawesome/fontawesome-free
Add the file paths in the angular.json file.
"styles": ["node_modules/#fortawesome/fontawesome-free/css/all.css"],
"scripts": ["node_modules/#fortawesome/fontawesome-free/js/all.js"]
for reference: https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers
Tats all..
hope this will help..
If you use scss you can simply import styles to your vendor.scss:
$fa-fort-path: "~#fontawesome/fontawesome-free/webfonts";
#import "~#fortawesome/fontawesome-free/scss/fontawesome";
#import "~#fortawesome/fontawesome-free/scss/regular";
#import "~#fortawesome/fontawesome-free/scss/solid";
#import "~#fortawesome/fontawesome-free/scss/brands";
And use it normally:
<span class="fab fa-refresh fa-spin fa-github" aria-hidden="true"></spin>
Mind the namespaces, fab for brands, fas for solid etc.
That was the best option for me.
Or you can use angular-fontawesome library.
I use this two solutions:
Large amount of used icons
Import main fontawesome.scss file.
Import preferred style file, e.g. regular.scss (both in angular.json or via #import).
Register default font set in module, so you don't have to define it for each icon:
constructor(private matIconRegistry: MatIconRegistry) {
matIconRegistry.setDefaultFontSetClass('far'); // or 'fas' for solid style etc.
}
Finally define icon line this:
<mat-icon fontIcon="fa-smile"></mat-icon>
Small amount of used icons
It is not necessary to import all icons, but you only need to define each icon separately in module. Other advantage are that you can define you own icon name for better clarity, combine icons with different styles (solid, duotones...) without loading another icon set, or simply add your own svg icons or logo.
constructor(private matIconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer) {
matIconRegistry.addSvgIcon('smile', sanitizer.bypassSecurityTrustResourceUrl('smile.svg'));
}
Icon:
<mat-icon svgIcon="smile"></mat-icon>
<fa-icon icon="fa-clipboard-check"></fa-icon>
Make sure FontAwesomeModule is imported in the container module of your component.
In case you need svg:
import { FontAwesomeModule } from '#fortawesome/angular-fontawesome';
import { library } from '#fortawesome/fontawesome-svg-core';
import {faClipboardCheck} from '#fortawesome/free-solid-svg-icons';
library.add(faClipboardCheck);
If You want to use Font Awesome icons inside <mat-icon> Just use as bellow,
<mat-icon><i class="fa fa-file-chart-line"></i></mat-icon>
** You should have imported the Font Awesome CSS or SCSS to you project
I downloaded font-awesome package and copied /webfonts folder and /css/all.css file to src/assets/. I added the path src/assets/css/all.css to the styles array in build options in my angular.json as shown below.
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"NAME_OF_PROJECT": {
"projectType": "application",
"schematics": {
"#schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/NAME_OF_PROJECT",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets",
"src/.well-known"
],
"styles": [
"src/styles.scss",
"src/assets/css/all.css",
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
}
}
}}
}
Now the font awesome icons are available to use in your angular application. I used class fa-2x to control the size of the icon. changing fontSet to "fal" will give you light version of font awesome.
<mat-icon fontSet="fa" class="fa-2x" fontIcon="fa-user" matBadge="8" matBadgeSize="medium" matBadgePosition="after" matBadgeColor="warn"></mat-icon>
Related
First of all, some facts:
Node.js requires that all local imports include the imported module's extension (e.g. import hello from './hello.js', not import hello from './hello').
TypeScript will compile imports with or without the .js extension, which means a missing .js extension is a runtime error.
TypeScript doesn't transform imports to add the .js extension or convert .ts to .js.
In my Node.js project, I want to make missing a missing .js extension be a build-time error using the import/extensions ESLint rule. However, when I enable this rule using the following configuration:
{
"root": true,
"env": {
"node": true
},
"parser": "#typescript-eslint/parser",
"plugins": [
"#typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:#typescript-eslint/eslint-recommended",
"plugin:#typescript-eslint/recommended"
],
"settings": {
"import/resolver": {
"typescript": {},
"node": {
"extensions": [".js"]
}
}
},
"rules": {
"import/extensions": ["error", "ignorePackages"]
}
}
running eslint gives me the following error:
/sandbox/src/index.ts
1:19 error Missing file extension "ts" for "./hello.js" import/extensions
Source files:
// index.ts
import hello from "./hello.js";
hello();
// hello.ts
export default function hello() {
console.log("Hello");
}
CodeSandbox link: https://codesandbox.io/s/elated-germain-13glp7
I fixed this with the following config:
{
"root": true,
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:#typescript-eslint/eslint-recommended",
"plugin:#typescript-eslint/recommended"
],
"rules": {
"import/extensions": ["error", "ignorePackages"],
"import/no-unresolved": "off"
}
}
The main thing is to disable the "import/no-unresolved" rule and remove "settings"."import/resolver"."node". ("import/no-unresolved" is redundant as unresolved imports are resolved at the compilation stage.) Other items removed here were already being added as a result of extending the #typescript-eslint plugins.
I found an eslint plugin that can fix missing .js extensions for imports in .ts files, instead of just showing an error:
https://github.com/AlexSergey/eslint-plugin-file-extension-in-import-ts
https://www.npmjs.com/package/eslint-plugin-file-extension-in-import-ts
Install:
npm i -D eslint-plugin-file-extension-in-import-ts
Add to .eslintrc file:
{
"plugins": [
"file-extension-in-import-ts"
],
"rules": {
"file-extension-in-import-ts/file-extension-in-import-ts": "error"
}
}
NOTE: I ran into an issue similar to https://github.com/import-js/eslint-plugin-import/issues/1292 when using this package, and it will incorrectly try to add .js extensions on these paths when fixing automatically.
You could try ts-add-js-extension package to append .js extension to the transpiled JavaScript files. After you install you can do
ts-add-js-extension add --dir={your-transpiled-outdir}
I use prettier with eslint in vs code as follow setting.
//.eslintrc
{
"parser": "babel-eslint",
"root": true,
"extends": [
"airbnb",
"plugin:vue/essential",
"plugin:prettier/recommended",
"eslint:recommended"
],
"rules": {
"no-console": 0
}
}
//.prettierc
{
"printWidth": 100,
"singleQuote": true,
"jsxBracketSameLine": true
}
but some eslint recommend conflict autoformatting from prettier.
prettier make code like this.
import { mapGetters, mapActions } from 'vuex'
(autosaving)
import {
mapGetters,
mapActions
} from 'vuex'
but now eslint draw red line.
// example
Replace `␍⏎··mapActions,␍⏎··mapGetters␍⏎` with `·mapActions,·mapGetters·`eslint(prettier/prettier)
I don't want eslint red line anywhere...
so I was found some document, but cannot found prettier setting..
how disable this red line?
Since prettier is very opinionated, it might cause trouble with es-lint sometimes. You might want to use a library like prettier-eslint
This will format your code with prettier, then try to fix it with eslint.
You can probably disable the conflicting rules as described in the prettier docs.
https://prettier.io/docs/en/eslint.html
They've mentioned adding
{ "extends": ["prettier"] }
to your .eslintrc.json might help along with other configuration.
$npm install -g #angular/cli
$ng new angular --routing --style=sass
$ng g c home
"apps": [
{
"styles": [
"styles.sass"
],
}
"defaults": {
"styleExt": "sass",
"component": {
}
}
I want to sass style in angular, I use angular cli, I try to generate component it returns with style with prefix css. May you help me to fixing that? Thanks in advance for your answer.
To override the default style, you can use the option --style [css|scss|sass]:
ng g c home --style=css
I just migrated from #angular/cli#1.0.3 to #angular/cli#1.4.2 and I am facing the same issue. Turns out it's due to a bug introduced in v1.4.1 so we can only wait for a new angular-cli release that will fix this bug.
In v1.4.1 also the apps.prefix is ignored but this was fixed in v1.4.2.
In the mean time, the workaround provided by #Derlin can be used.
github issues on this topic:
https://github.com/angular/angular-cli/issues/7624
https://github.com/angular/angular-cli/issues/7682
https://github.com/angular/angular-cli/issues/7644
https://github.com/angular/angular-cli/issues/7647
https://github.com/angular/angular-cli/issues/7522
update:
The issue is fixed in #angular/cli#1.4.3. Check this release note.
#angular/cli: Generating component considers default style extension
for project now
Here is my defaults that works :
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
Otherwise, you can just rename it.
I'm having difficulty setting user settings for SublimeLinter in SublimeText3. I've checked here: http://www.sublimelinter.com/en/latest/settings.html
I've tried setting my user settings, and setting "max-line-length" to 80 (the default is 100):
{
"user": {
"debug": false,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"pylint": {
"#disable": false,
"args": [],
"disable": "",
"enable": "",
"excludes": [],
"max-line-length": 80,
"paths": [],
"rcfile": "",
"show-codes": false
}
},
"mark_style": "outline",
"no_column_highlights_line": true,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"php": "html",
"python django": "python"
},
"warning_color": "DDB700",
"wrap_find": true
}
}
However, this setting is not applied. I have closed and re-opened sublime text. How do I get this setting to be applied? Thanks.
The syntax you are using seems to work for some linters, however, as far as I know it doesn't works for pylint.
Anyway, for using pylint from Sublime Text you can use the command argument --max-line-length=N,
so change
"args": []
for
"args": ["--max-line-length=90"]
In addition, if you do this, remove the max-line-length property.
Edit: where to place SublimeLinter settings.
You can learn about it in the SublimeLinter settings documentation
I used the user-settings-file, that you can usually find using the following menu option: Preferences > Package Settings > SublimeLinter > Settings-User. For this purpose you need to add the option inside linters/pylint:
{
"user": {
"linters": {
"pylint": {
// "exampleOtion": "exampleValue",
"args": ["--max-line-length=90"]
}
}
}
}
Please note that probably your config file is similar to the one in the question, so you just need to add the new option inside "pylint" without breaking the JSON format
As this message continues to appear regularly on the first page of Google and SublimeLinter has changed a lot, here is my solution:
I enter "pref lint" or "preferences linter" in the Command Palette in sublime text 3 (screenshot) to open the preferences file.
Here's the SublimeLinter.sublime-settings default config file I am using (W0312 is for using tabs instead of spaces):
// SublimeLinter Settings - User
{
"linters": {
"pylint": {
"filter_errors": ["warning:", "W0312"]
}
}
}
I use pylint-messages to find the right error/warning codes, with the help of the search box.
I have some qunit tests setup to test my code that extensively uses requirejs. I use Chutzpah to perform the test running within VS. Everything works fine if I run the tests in the browser but not from within VS only. It seems to be ignoring my require.config call. If I change my references in my files to not point to shims but directly to files, it will work, but that breaks other things within my code.
Does anyone have this working? If so, how? I have looked at their example code but it doesn't use require.config and shims.
Start from this tutorial.
To run a config, with shims, just add a reference to your config file in chutzpah.json. Example below, slightly simplified for readability.
The chutzpah.json file
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References": [
{ "Path": "../Scripts/Components/RequireJS/require.js" },
{ "Path": "config.js" }
]
}
The config.js file
require.config({
"paths": {
"jquery": "../Scripts/jquery-2.1.4",
"jquery-linq": "../Scripts/jquery.linq",
"signalr": "../Scripts/jquery.signalR-2.2.0",
"signalrhubs": "../Scripts/mock-signalr-hubs",
"knockout": "../Scripts/knockout-3.3.0",
"constants": "../Scripts/constants",
"HomeVm": "Source/HomeVm"
},
"shim": {
"jquery.linq": {
"deps": ["jquery"]
},
"bootstrap": {
"deps": ["jquery"]
},
"signalr": {
"deps": ["jquery"]
}
}
});