The updated version of Angular from 13 to 16 has implemented a new default value for primary colors

I recently upgraded my angular (+material-ui) system from version 13 to 16, and encountered an issue with the primary color of my custom theme. It seems that the value is no longer being recognized and defaults to blue. After updating the angular version, I included "@use "@angular/material" as mat;" along with values for typography and density to address build warnings.

Below is a snippet of my custom-theme.scss:

@use "@angular/material" as mat;

$my-orange: mat.define-palette(
  mat.$pink-palette,
  (
    50: green,
    100: green,
    200: green,
    300: green,
    400: green,
    500: green,
    600: green,
    700: green,
    800: green,
    900: green,
    A100: green,
    A200: green,
    A400: green,
    A700: green,
  )
);

$my-accent: mat.define-palette(
  mat.$blue-grey-palette,
  (
    50: white,
    100: white,
    200: white,
    300: white,
    400: white,
    500: white,
    600: white,
    700: white,
    800: white,
    900: white,
    A100: white,
    A200: white,
    A400: white,
    A700: white,
  )
);

$my-primary: mat.define-palette(mat.$pink-palette, 500);
$my-accent: mat.define-palette(mat.$blue-grey-palette, A200, A100, A400);

$my-theme: mat.define-light-theme(
  (
    color: (
      primary: $my-primary,
      accent: $my-accent,
    ),
    typography: mat.define-typography-config(),
    density: 0,
  )
);

@function theme() {
  @return $my_theme;
}

To import the custom theme in styles.scss:

@use "@angular/material" as mat;
@use "./custom-theme";

@include mat.core();

@include mat.all-component-themes(custom-theme.theme());

Upon running npm run start, the following error messages are displayed: 1.

Undefined function.
   ╷
   │ @include mat.all-component-themes(custom-theme.theme());
   │                                   ^^^^^^^^^^^^^^^^^^^^
   ╵
  src/styles.scss 19:35  root stylesheet
(50: #80ba24, 100: #80ba24, 200: #80ba24, 300: #80ba24, 400: #80ba24, 500: #80ba24, 600: #80ba24, 700: #80ba24, 800: #80ba24, 900: #80ba24, A100: #80ba24, A200: #80ba24, A400: #80ba24, A700: #80ba24) isn't a valid CSS value.
   ╷
   │   @error 'Hue "' + $hue + '" does not exist in palette. Available hues are: ' + map.keys($palette);
   │          ^^^^^^^^^^^^^^
   ╵
  node_modules/@angular/material/core/theming/_theming.scss 47:10  -get-color-from-palette()
  node_modules/@angular/material/core/theming/_theming.scss 70:14  define-palette()
  src/custom-theme.scss 3:13                                       root stylesheet

Answer №1

I came across a few errors:

  1. It's important not to use @include mat.core() more than once as specified in the Angular Material guidelines.
  2. Avoid using @import and opt for @use instead, as advised by Sass.
  3. You forgot to run the all-component-themes mixin to apply your custom theme to all components.

_custom-theme.scss

@use '@angular/material' as mat;

$my-primary: mat.define-palette(mat.$pink-palette, 500);
$my-accent: mat.define-palette(mat.$blue-grey-palette, A200, A100, A400);

$my-theme: mat.define-light-theme((
 color: (
   primary: $my-primary,
   accent: $my-accent,
 ),
 typography: mat.define-typography-config(),
 density: 0,
));

@function theme() {
  @return $my_theme;
}

style.scss

@use '@angular/material' as mat;
@use './custom-theme';

@include mat.core();

@include mat.all-component-themes(custom-theme.theme());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sliding panel, perhaps?

I've been working on a small project and I've managed to create this panel, but I'm looking to change the position of the "tab" to something similar to this Can anyone help me out? I'm still new to all of this~ http://jsfiddle.net/ ...

Module fails to load in the proper sequence

As a .NET developer who is relatively new to modern client-side web applications, I am currently working on developing an Angular2 charting application using Chart.js. The modules are being loaded with SystemJS. Below is the content of my systemjs.config. ...

How can you incorporate a custom button into the controlBar on videoJS in responsive mode?

The video player I have created using videoJS includes custom buttons in the control bar. These buttons are not clickable when viewed on mobile or tablet devices without forcing them to work. let myButton = player?.controlBar.addChild('button'); ...

When the browser is refreshed, jQuery will automatically scroll the window down

I created a div that matches the height and width of the window to simulate a "home screen." When scrolling down to view the content, everything works fine. However, after refreshing the browser, it automatically scrolls back to where you were before. I wa ...

Dynamically load components within a modal window

I am looking for a way to dynamically load a custom component inside a modal while keeping it as flexible as possible. Here is an example : -HTML CODE- <button id="floating_button" class="floating_button animation_floating_in" (click)="loadCustomComp ...

Deploying an Angular application in a NodeJS environment using Azure DevOps

Can Azure DevOps Pipelines be used to automate the deployment of an Angular application to NodeJS or an on-premise WebServer? ...

Error encountered when creating a new project using ASP.NET Core (.NET 5) and Angular 11

When I start a new ASP.NET Core Web API + Angular project in Visual Studio by using: dotnet new angular, it sets up a .NET 5 project with an Angular 8.2 project in the ClientApp folder. After hitting F5, everything runs smoothly. However, I want to work ...

Using Angular 2 to efficiently recycle a subcomponent with the same form across multiple parent components while maintaining its state

I've been struggling to find someone with the same issue as me, even though the title may seem familiar. Perhaps I need help rephrasing my question? Here's an explanation: Use case: I have multiple routes (only 2 in the example below) set up fo ...

Obtain redirected JSON data locally using Angular 5

Currently, I am working on retrieving JSON data which will be sent to my localhost through a POST method. The SpringBoot API controller will validate the JSON content before forwarding it to my localhost. My task is to intercept this JSON data when it is t ...

Initial position of the range slider in IONIC 2

I have been searching the web extensively to find a solution to this particular issue. I am working with a range slider and trying to set its default starting values, but so far, I haven't had any luck. I've checked both the official documentatio ...

What are the steps for creating personalized sliders with WordPress?

Seeking guidance on how to code WP Template files to enable control from the WP dashboard for adding or removing slider images. A sample code snippet is provided below. <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indi ...

Unique background image for every individual page

For my mobile app development using Jquery Mobile, I have implemented a custom theme but now want to vary the background images for different sections. My current code looks like this: .ui-overlay-a, .ui-page-theme-a, .ui-page-theme-a .ui-panel-wrapper { ...

I need to adjust the alignment of the text within my list item that includes a time element

I am struggling with aligning my elements vertically downward as the text following the "-" appears disorganized. I attempted to enclose the time tags within div elements and align them so that they evenly occupy space, but this approach did not work. Ins ...

Creating a Sticky Header and Footer with Responsive Design: Ensuring Content Div Expansion between Them

Greetings. I am working on creating a simple responsive HTML layout as described below: HTML: <div id="header"></div> <div id="content"></div> <div id="footer"></div> CSS: #header{ wi ...

javascript highchart image carousel

I am currently working on a visual chart project using the JavaScript library highchart. After setting up my chart with some dummy data, I am looking to incorporate functionality that allows for triggering an image slide based on the chart data. Specific ...

Transitioning React Hover Navbar Design

I'm currently revamping a click-to-open navbar into a hover bar for a new project. I have successfully implemented the onMouseEnter and onMouseLeave functions, allowing the navbar to open and close on mouse hover. However, I am facing an issue with ad ...

Guide to choosing and unchoosing a div / button using angularJs

I am attempting to create a functionality where items are displayed in a div instead of a list. When an item is clicked, the background color of the div changes and the item is added to a column. Clicking on the item again will revert it back to its origin ...

Jasmine: utilizing unit test to spy on the invocation of a nested function

When running unit tests for an Angular app, I need to spy on a function called func1 to check if it is being called. However, within func1 there is a call to func2 and I also want to spy on that to see if it is being called. How should I structure my unit ...

Why is it that using div with a 100% width doesn't behave as one would anticipate?

Learning CSS has been an interesting journey so far. It's not always as intuitive as one might think, especially in web development. :) I recently attempted to create a simple, static progress bar using the following HTML file: <html> <he ...

Verify if the second list item contains the "current" class

When displaying a list of blog items on the blog page, I am using grid-column: 1 / -2;. In the first row, the first blog item spans two columns while the second and subsequent rows display three items in each row. This setup works well, but when moving to ...