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

A discrepancy has arisen as the value within the array structure is being altered

I am facing an issue with the array structure of an object in my Angular front-end code. When I add values to the array based on selection, the object looks like this: todayRates: 10 yesterdayRates: 5 to: Array(1) 0: [3] length: 1 __proto__: Array(0) __pro ...

Stopping HTTP observable subscriptions in Angular 2 Service

What is the most effective way to unsubscribe from an HTTP subscription within an Angular2 service? I currently handle it this way, but I'm unsure if it's the optimal approach. import { Injectable } from "@angular/core"; import { Http } from "@ ...

Innovative ways to design a responsive carousel with Bootstrap

My goal was to create a slider with divisions inside a bootsrap carousel, and here is what I did. However, I am looking for guidance on how to adjust it so that on screens smaller than sm (of bootstrap), there are only two divisions in one carousel, and a ...

Retrieving a string value from a child route in Angular 2

Looking to set the header title from a child route view... In the parent component: @Component({ selector: 'parent-component', template: ` <header>{{headerTitle}}</header> <router-outlet></router-outlet ...

Storing images in Azure Blob Storage

I am currently using Angular 2 on the frontend and Node.js for the backend. I am facing an issue while attempting to upload a file to Azure storage blob container. Whenever I try to send the image to the API, an error occurs. Any assistance in this matter ...

Adjusting Bootstrap CSS Styles

After recently installing bootstrap 3.0 on my website and experimenting with it, I have a few questions. I am looking to customize certain aspects of the jumbotron (and other classes) in my personal .css file named "mycss.css". Here is the code I have add ...

What is the best way to position the sign-in modal form on the top right corner of my website?

Hey there, I'm facing a bit of an issue and can't seem to figure out what went wrong. Recently, I inserted a Bootstrap Sign In modal in my HTML file. Here's the code: <div class="text-center"> <a href="" class ...

Angular chat integration

In my application, I have a parent component called "chat" with two child components - "sidebar" (which displays the user list) and "conversation detail" (which shows the chat with each user). The functionality I am aiming for is that when a user is clicke ...

Variety of HTML tags yet identical ID

Is it possible to have two elements with different types – such as a div and an ul with the same id in HTML? Here is an example of HTML code: <div id="articleOptions"> <ul id="articleOptions"> <li>Share</li> ...

Child element casting shadow over parent element

I am currently using box shadow for both the parent (.map) and child (.toggle-button): .map { position: fixed; top: 20px; right: 0; width: 280px; height: 280px; z-index: 9999; box-shadow: 0px 1px 6px 0px rgba(0,0,0,0.3); } .map ...

Show a component on click event in Angular 4

Looking for a solution to create an event on a button click that triggers another component? When clicked again, the component should be reduced with a part always remaining visible. While I am currently using [ngClass]='hidden' within the same c ...

Issue with ngbCollapse feature when attempting to collapse multiple dynamically generated divs on a single page

When dynamically generating ngbCollapse in a main loop that checks for the presence of the Sun in a JSON object, if the Sun is not there, it provides an option to Add_Sun(). Since it is within a loop, it allows adding a sun to every row. When clicking th ...

Having trouble removing or updating Angular Cli on a MAC device

Struggling with uninstalling angular cli on mac. npm remove -g @angular/cli https://i.sstatic.net/1JVxX.png ...

What kind of impact on performance can be expected when using index.ts in a Typescript - Ionic App?

When setting up the structure of a standard Ionic app, it typically looks like this: app pages ----page1 ---------page1.ts ----page2 ---------page2.ts If I were to include an index.ts file in the pages folder as follows: pages/index.ts export { Page1 } ...

The dimensions of the div element are adjusting as I scroll on Firefox Mobile, however, there is a way to prevent this from happening using Angular

I've been conducting tests on my Angular application on various mobile devices. While everything seems to function properly on Chrome and Safari, an issue arises when it comes to Firefox: during scrolling, the browser's toolbar and URL bar appear ...

What could be hindering the animation of this button?

I found this snippet on a coding blog, where the design looked perfect: However, when I tried implementing it, the button displayed a static gradient instead of animated. Additionally, aligning the text in the center vertically seems to be trickier than e ...

calc() not supported on IE11

Why is IE11 unable to calculate this? The console shows it as invalid (highlighted in red) h6 { ... font-size: calc(calc((( (20 / 16) / 16 - 1 / 16) * (100vw - 20rem) / (992 / 16 - 20) + 1 / 16 * 1rem) * 16)); ... } However, the following code works ...

What is causing the left scroll to not work with negative values?

My design features three blocks stacked on top of each other with an additional block at the bottom below the middle. Left <--------> Middle<---------->Right -----------------Bottom------------------ I have a couple of queries. Why is scr ...

What could be causing the extra room at the bottom of my webpage?

I've been teaching myself how to create responsive websites using Zurb's Foundation 6. I've successfully built a simple website, but I'm facing an issue with spacing at the bottom of the page. The problematic areas are the "pagination" ...

The CSS isn't loading properly once the file is uploaded to the server using FileZilla or cPanel

After uploading the file.css file to the server using both FileZilla and cPanel, I noticed that when I visit the website, the CSS is not being applied properly. Specifically, I changed padding-left: 10px; However, upon viewing the Page source, it appears ...