skip to Main Content

Why does my expansion panel and form fields have no style or functionality?

I have imported the module and imported angular theme in my style.scss.

MatIcon and the other components I have tested don’t seem to work at all either.

Here is all the code I could think to include, any help would be appreciated!

Bugged expansion panel:
enter image description here

I also get this error when I attempt to open/close the expansion panel:
enter image description here

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { TestComponent } from './test/test.component';

@NgModule({
  declarations: [
    AppComponent,
    TestComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    MatExpansionModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

style.scss:

@import "../node_modules/@angular/material/theming";

body {
  --bgColor: rgb(44 56 72);
  --lightOrange: #f55a04;
  --medOrange: #f53303;
  background-color: var(--bgColor);
}


.shadow-border {
  box-shadow: 0 3px 1px -2px rgb(0 0 0 / 10%), 0 1px 1px rgb(0 0 0 / 10%), 0 1px 2px rgb(0 0 0 / 10%) !important;
  border: 1px solid #435162;
  border-radius: 12px;
}

component html

<div class="container shadow-border">
  <mat-accordion>
    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Personal data
        </mat-panel-title>
        <mat-panel-description>
          Type your name and age
        </mat-panel-description>
      </mat-expansion-panel-header>
      <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eaque culpa cumque dolore molestias ad. Nemo cum odit autem nulla. Nobis corporis eius officiis quam, saepe fugiat optio ea beatae pariatur!</p>
    </mat-expansion-panel>
  </mat-accordion>
</div>

package.json

{
  "name": "animation-tool",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.0.0",
    "@angular/common": "^14.0.0",
    "@angular/compiler": "^14.0.0",
    "@angular/core": "^14.0.0",
    "@angular/forms": "^14.0.0",
    "@angular/material": "^7.0.0",
    "@angular/platform-browser": "^14.0.0",
    "@angular/platform-browser-dynamic": "^14.0.0",
    "@angular/router": "^14.0.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.0.1",
    "@angular/cli": "~14.0.1",
    "@angular/compiler-cli": "^14.0.0",
    "@types/jasmine": "~4.0.0",
    "jasmine-core": "~4.1.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.7.2"
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution eventually. I deleted the project and started a new one. Steps I followed to avoid error:

    ng new [project-name]
    cd [project-name]
    npm install
    ng add @angular/material
    

    then I went into package.json and changed the cdk and material versions to 14.0.0

    npm install
    ng add @angular/material
    

  2. In your dependencies, you’re trying to use Angular Material 7 with Angular 14. Try Angular material 14 instead. Also, scss import should be:

    @import "~@angular/material/theming";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search