DEV Community

Cover image for 💡How to Integrate Materialize-CSS with Angular (Without the Headache!)
Nelson Garcia Dev.
Nelson Garcia Dev.

Posted on

3 1 1

💡How to Integrate Materialize-CSS with Angular (Without the Headache!)

After struggling, crying (a little), and spending hours debugging, I finally managed to integrate Materialize-CSS into my Angular project. 😅

Along the way, I encountered several unexpected bugs and compatibility issues that nearly made me give up.

If you've ever tried to use Materialize-CSS in Angular and couldn't get it to work — or you're just starting out and want to avoid the pain — this post is for you! 🚀

I'll walk you through how to integrate Materialize-CSS into your Angular project in a simple and effective way, without the usual frustration.

Spoiler: It's not just “install and import.” There are a few key tricks that make all the difference.

Let'get into it.

Step-by-step: How to Integrate Materialize-CSS in Angular

first step:

  1. Installing dependecies. First, make sure you have jQuery and its type definitions installed. Then, install Materialize-CSS and its types as well.
# jQuery
npm install jquery

# jQuery types
npm install --save-dev @types/jquery

# Materialize-CSS
npm install materialize-css

# Materialize-CSS types
npm install --save-dev @types/materialize-css
Enter fullscreen mode Exit fullscreen mode
  1. Configuring angular.json You need to include both jQuery and Materialize-CSS in your angular.json file.
"scripts": [
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/materialize-css/dist/js/materialize.min.js"
],
"styles": [
  "node_modules/materialize-css/dist/css/materialize.min.css"
]
Enter fullscreen mode Exit fullscreen mode
  1. Importing the dependencies You can import the libraries where you'll use them — either in a global module or in a specific component:
import * as $ from 'jquery';
import * as M from 'materialize-css';
Enter fullscreen mode Exit fullscreen mode

for instance:

Image description

  1. Initializing Materialize Components Many Materialize components require initialization via JavaScript. Do this inside the ngOnInit() lifecycle hook:

Image description

This ensures everything is ready when your component is loaded.

  1. Styling your Template Now you can freely use Materialize's CSS classes in your templates. Here's a simple example:

Image description

  1. Using JS-Dependent Components For components that depend on JavaScript (like modals, tooltips, dropdowns, etc.), you'll need to initialize them individually:
  • In your component.ts:

Image description

  • In your tempate (html code)

Image description

Thanks so much for reading! I hope this guide saves you time (and sanity 😅).

If you want to check out the working code, it's available on GitHub:
👉 Repo Link

✍️ Written by: Nelson Manuel Garcia
Feel free to reach out if you have questions or want to connect! 🎧💻

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay