Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Metronic with PrimeNg library


Hi! I'm ușing Metronic (Angular version) and i installed PrimeNg. All good until i found ouț that primeng styles are override by bootstrap reboot css within metronic styles. How can i make PrimeNg on top of that? I tried with layers, but not working.
Can you help me?
Thanks în advance!


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Using CSS layers can help manage the order of your styles. Ensure that PrimeNG styles are loaded after Bootstrap's reboot CSS.
@block blast



Hi Ana

To switch PrimeNG themes with Metronic's theme mode switcher:
Include both dark and light PrimeNG theme files in Angular.json.
Dynamically change the <link> tag for PrimeNG themes based on the mode selected.
Example:


switchTheme(theme: "dark" | "light") {
const themeLink = document.getElementById("primeng-theme") as HTMLLinkElement;
themeLink.href = theme === "dark"
? "path-to-dark-theme.css"
: "path-to-light-theme.css";
}


Add the PrimeNG theme link in index.html:


<link  rel="stylesheet" href="path-to-light-theme.css">


This approach will allow PrimeNG and Metronic to switch between dark and light modes simultaneously.



Thanks for fast replying. I have one more question. I need to implement in the theme mode switcher of Metronic a switch for primeng template too (dark/light css files) . How do i switch css if they are loaded via angular.json?


Hi Ana Sorlea

You can try the following approaches:

  1. Load PrimeNG Styles After Bootstrap Styles Check that PrimeNG styles are loaded after the Bootstrap Reboot and other Metronic styles in the angular.json file:
"styles": [
  "src/styles.css", 
  "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
  "node_modules/primeicons/primeicons.css",
  "node_modules/primeng/resources/themes/saga-blue/theme.css", 
  "node_modules/primeng/resources/primeng.min.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css"
]

PrimeNG styles should be listed after the Bootstrap styles to override conflicting rules.

  1. Use View Encapsulation In Angular, you can use ViewEncapsulation to encapsulate component styles and avoid unwanted style overrides. Add the following line in the component decorator of the component where PrimeNG styles are being overridden:
import { ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html',
  styleUrls: ['./example.component.css'],
  encapsulation: ViewEncapsulation.None // Disables Angular's CSS encapsulation
})
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(