Angular 2 - PrimeNg style not working

为君一笑 提交于 2019-12-03 13:13:20

I found a tutorial that uses PrimeNg with Angular CLI that worked for me.

I added the font-awesome.min.css stylesheet to index.html.

Then the theme I wanted (e.g. "../node_modules/primeng/resources/themes/omega/theme.css",) to angular-cli.json file in the "styles" [...] section.

Smaillns

in the style.css file , add your imports for example :

 @import '../node_modules/primeng/resources/themes/omega/theme.css'

if you have correctly downloaded PrimeNG, it should work now

just a bit note : be sure you have imported the primeNG modules in the correct place (In fact, we import modules not components, take care;)

According to the setup instructions you should use the following:

<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/themes/omega/theme.css" />
<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/primeng.min.css" />
<link rel="stylesheet" type="text/css" href="YOUR_PATH/font-awesome.min.css" />

notice that the path starts with:

href="/node_modules/primeng/resources/themes/omega/theme.css" 

not:

href="../node_modules/primeng/resources/themes/omega/theme.css"

Hope this helps! :)

What are you using for project structure if you are using cli you should add those to styles.css. In overall they should go into the bundle.

Just upgraded to PrimeNG 6.1.6 and got this error.

Looks like with this release the themes have stopped using theme.css in favor of theme.scss. So, you will have to reference "node_modules/primeng/resources/themes/omega/theme.scss" (instead of "theme.css") in the "styles" section of angular.json AND …

You will need to npm rebuild node-sass.

Ankita

I resolve my problem by remove rel="stylesheet" type="text/css" from index.html and also added below imports to styles.css :

@import '~primeicons/primeicons.css';
@import '~primeng/resources/themes/nova-light/theme.css';
@import '~primeng/resources/primeng.min.css';
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!