Angular Material styles not being applied correctly












0















Any ideas why the angular material styles are not being applied correctly?



I know there are a lot of questions on this but I can't seem to find one that resolved my problem.
I have used angular material with no problem for several projects but can't seem to figure out what is going on here.

I am probably overlooking something simple but just can't see it. I have just upgraded to angular 7 so it could be related to that.



This is my dialog which just displays in the parent page with weird or no styling. It is doing something as the buttons have changed slightly as you can see compared to the cancel button.



enter image description here



<div>
<h4 mat-dialog-title>New Course Item</h4>
</div>
<div mat-dialog-content>
<div>
<div>
<mat-form-field>
<mat-label>Title</mat-label>
<input type="text" [(ngModel)]="newCourseItem.title" #title="ngModel" matInput required placeholder="Title" name="title"/>
<mat-error *ngIf="title.hasError('required')">This field is required</mat-error>
</mat-form-field>
</div>
<div>
<button (click)="this.dialogRef.close()">Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="newCourseItem" cdkFocusInitial>Add New</button>
</div>
</div>
</div>

import { CourseItem } from './../../../../models/course-item';
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
selector: 'app-new-course-item-dialog',
templateUrl: './new-course-item-dialog.component.html',
styleUrls: ['./new-course-item-dialog.component.css']
})
export class NewCourseItemDialogComponent implements OnInit {
newCourseItem: CourseItem = new CourseItem();

constructor(public dialogRef: MatDialogRef<NewCourseItemDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }

ngOnInit() {
}

}

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { MatInputModule, MatDialogModule, MatButtonModule, MatFormFieldModule } from '@angular/material';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
CourseAdminComponent,
NewCourseItemDialogComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
MatButtonModule,
MatInputModule,
MatFormFieldModule
],
providers: [
AuthService,
DataService
],
bootstrap: [AppComponent],
entryComponents: [
NewCourseItemDialogComponent
]
})
export class AppModule { }


Angular CLI: 7.0.5
Node: 10.7.0
OS: win32 x64
Angular: 7.0.4
... animations, cdk, common, core, material

Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.10.5
@angular-devkit/build-optimizer 0.10.5
@angular-devkit/build-webpack 0.10.5
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cli 7.0.5
@angular/compiler 7.0.3
@angular/compiler-cli 7.0.3
@angular/flex-layout 7.0.0-beta.19
@angular/forms 7.0.3
@angular/http 7.0.3
@angular/language-service 7.0.3
@angular/platform-browser 7.0.3
@angular/platform-browser-dynamic 7.0.3
@angular/router 7.0.3
@ngtools/webpack 7.0.5
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1









share|improve this question




















  • 1





    Have you included the CSS file in your angular.json file?

    – user184994
    Nov 20 '18 at 21:57






  • 2





    Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

    – SiddAjmera
    Nov 20 '18 at 21:59











  • You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

    – MadMac
    Nov 20 '18 at 22:18
















0















Any ideas why the angular material styles are not being applied correctly?



I know there are a lot of questions on this but I can't seem to find one that resolved my problem.
I have used angular material with no problem for several projects but can't seem to figure out what is going on here.

I am probably overlooking something simple but just can't see it. I have just upgraded to angular 7 so it could be related to that.



This is my dialog which just displays in the parent page with weird or no styling. It is doing something as the buttons have changed slightly as you can see compared to the cancel button.



enter image description here



<div>
<h4 mat-dialog-title>New Course Item</h4>
</div>
<div mat-dialog-content>
<div>
<div>
<mat-form-field>
<mat-label>Title</mat-label>
<input type="text" [(ngModel)]="newCourseItem.title" #title="ngModel" matInput required placeholder="Title" name="title"/>
<mat-error *ngIf="title.hasError('required')">This field is required</mat-error>
</mat-form-field>
</div>
<div>
<button (click)="this.dialogRef.close()">Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="newCourseItem" cdkFocusInitial>Add New</button>
</div>
</div>
</div>

import { CourseItem } from './../../../../models/course-item';
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
selector: 'app-new-course-item-dialog',
templateUrl: './new-course-item-dialog.component.html',
styleUrls: ['./new-course-item-dialog.component.css']
})
export class NewCourseItemDialogComponent implements OnInit {
newCourseItem: CourseItem = new CourseItem();

constructor(public dialogRef: MatDialogRef<NewCourseItemDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }

ngOnInit() {
}

}

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { MatInputModule, MatDialogModule, MatButtonModule, MatFormFieldModule } from '@angular/material';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
CourseAdminComponent,
NewCourseItemDialogComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
MatButtonModule,
MatInputModule,
MatFormFieldModule
],
providers: [
AuthService,
DataService
],
bootstrap: [AppComponent],
entryComponents: [
NewCourseItemDialogComponent
]
})
export class AppModule { }


Angular CLI: 7.0.5
Node: 10.7.0
OS: win32 x64
Angular: 7.0.4
... animations, cdk, common, core, material

Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.10.5
@angular-devkit/build-optimizer 0.10.5
@angular-devkit/build-webpack 0.10.5
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cli 7.0.5
@angular/compiler 7.0.3
@angular/compiler-cli 7.0.3
@angular/flex-layout 7.0.0-beta.19
@angular/forms 7.0.3
@angular/http 7.0.3
@angular/language-service 7.0.3
@angular/platform-browser 7.0.3
@angular/platform-browser-dynamic 7.0.3
@angular/router 7.0.3
@ngtools/webpack 7.0.5
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1









share|improve this question




















  • 1





    Have you included the CSS file in your angular.json file?

    – user184994
    Nov 20 '18 at 21:57






  • 2





    Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

    – SiddAjmera
    Nov 20 '18 at 21:59











  • You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

    – MadMac
    Nov 20 '18 at 22:18














0












0








0








Any ideas why the angular material styles are not being applied correctly?



I know there are a lot of questions on this but I can't seem to find one that resolved my problem.
I have used angular material with no problem for several projects but can't seem to figure out what is going on here.

I am probably overlooking something simple but just can't see it. I have just upgraded to angular 7 so it could be related to that.



This is my dialog which just displays in the parent page with weird or no styling. It is doing something as the buttons have changed slightly as you can see compared to the cancel button.



enter image description here



<div>
<h4 mat-dialog-title>New Course Item</h4>
</div>
<div mat-dialog-content>
<div>
<div>
<mat-form-field>
<mat-label>Title</mat-label>
<input type="text" [(ngModel)]="newCourseItem.title" #title="ngModel" matInput required placeholder="Title" name="title"/>
<mat-error *ngIf="title.hasError('required')">This field is required</mat-error>
</mat-form-field>
</div>
<div>
<button (click)="this.dialogRef.close()">Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="newCourseItem" cdkFocusInitial>Add New</button>
</div>
</div>
</div>

import { CourseItem } from './../../../../models/course-item';
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
selector: 'app-new-course-item-dialog',
templateUrl: './new-course-item-dialog.component.html',
styleUrls: ['./new-course-item-dialog.component.css']
})
export class NewCourseItemDialogComponent implements OnInit {
newCourseItem: CourseItem = new CourseItem();

constructor(public dialogRef: MatDialogRef<NewCourseItemDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }

ngOnInit() {
}

}

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { MatInputModule, MatDialogModule, MatButtonModule, MatFormFieldModule } from '@angular/material';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
CourseAdminComponent,
NewCourseItemDialogComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
MatButtonModule,
MatInputModule,
MatFormFieldModule
],
providers: [
AuthService,
DataService
],
bootstrap: [AppComponent],
entryComponents: [
NewCourseItemDialogComponent
]
})
export class AppModule { }


Angular CLI: 7.0.5
Node: 10.7.0
OS: win32 x64
Angular: 7.0.4
... animations, cdk, common, core, material

Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.10.5
@angular-devkit/build-optimizer 0.10.5
@angular-devkit/build-webpack 0.10.5
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cli 7.0.5
@angular/compiler 7.0.3
@angular/compiler-cli 7.0.3
@angular/flex-layout 7.0.0-beta.19
@angular/forms 7.0.3
@angular/http 7.0.3
@angular/language-service 7.0.3
@angular/platform-browser 7.0.3
@angular/platform-browser-dynamic 7.0.3
@angular/router 7.0.3
@ngtools/webpack 7.0.5
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1









share|improve this question
















Any ideas why the angular material styles are not being applied correctly?



I know there are a lot of questions on this but I can't seem to find one that resolved my problem.
I have used angular material with no problem for several projects but can't seem to figure out what is going on here.

I am probably overlooking something simple but just can't see it. I have just upgraded to angular 7 so it could be related to that.



This is my dialog which just displays in the parent page with weird or no styling. It is doing something as the buttons have changed slightly as you can see compared to the cancel button.



enter image description here



<div>
<h4 mat-dialog-title>New Course Item</h4>
</div>
<div mat-dialog-content>
<div>
<div>
<mat-form-field>
<mat-label>Title</mat-label>
<input type="text" [(ngModel)]="newCourseItem.title" #title="ngModel" matInput required placeholder="Title" name="title"/>
<mat-error *ngIf="title.hasError('required')">This field is required</mat-error>
</mat-form-field>
</div>
<div>
<button (click)="this.dialogRef.close()">Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="newCourseItem" cdkFocusInitial>Add New</button>
</div>
</div>
</div>

import { CourseItem } from './../../../../models/course-item';
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
selector: 'app-new-course-item-dialog',
templateUrl: './new-course-item-dialog.component.html',
styleUrls: ['./new-course-item-dialog.component.css']
})
export class NewCourseItemDialogComponent implements OnInit {
newCourseItem: CourseItem = new CourseItem();

constructor(public dialogRef: MatDialogRef<NewCourseItemDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }

ngOnInit() {
}

}

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { MatInputModule, MatDialogModule, MatButtonModule, MatFormFieldModule } from '@angular/material';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
CourseAdminComponent,
NewCourseItemDialogComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
MatButtonModule,
MatInputModule,
MatFormFieldModule
],
providers: [
AuthService,
DataService
],
bootstrap: [AppComponent],
entryComponents: [
NewCourseItemDialogComponent
]
})
export class AppModule { }


Angular CLI: 7.0.5
Node: 10.7.0
OS: win32 x64
Angular: 7.0.4
... animations, cdk, common, core, material

Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.10.5
@angular-devkit/build-optimizer 0.10.5
@angular-devkit/build-webpack 0.10.5
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cli 7.0.5
@angular/compiler 7.0.3
@angular/compiler-cli 7.0.3
@angular/flex-layout 7.0.0-beta.19
@angular/forms 7.0.3
@angular/http 7.0.3
@angular/language-service 7.0.3
@angular/platform-browser 7.0.3
@angular/platform-browser-dynamic 7.0.3
@angular/router 7.0.3
@ngtools/webpack 7.0.5
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1






angular angular-material angular7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '18 at 10:39









Goncalo Peres

1,4541519




1,4541519










asked Nov 20 '18 at 21:52









MadMacMadMac

367




367








  • 1





    Have you included the CSS file in your angular.json file?

    – user184994
    Nov 20 '18 at 21:57






  • 2





    Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

    – SiddAjmera
    Nov 20 '18 at 21:59











  • You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

    – MadMac
    Nov 20 '18 at 22:18














  • 1





    Have you included the CSS file in your angular.json file?

    – user184994
    Nov 20 '18 at 21:57






  • 2





    Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

    – SiddAjmera
    Nov 20 '18 at 21:59











  • You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

    – MadMac
    Nov 20 '18 at 22:18








1




1





Have you included the CSS file in your angular.json file?

– user184994
Nov 20 '18 at 21:57





Have you included the CSS file in your angular.json file?

– user184994
Nov 20 '18 at 21:57




2




2





Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

– SiddAjmera
Nov 20 '18 at 21:59





Add @import "~@angular/material/prebuilt-themes/indigo-pink.css"; to your styles.css if you haven't already.

– SiddAjmera
Nov 20 '18 at 21:59













You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

– MadMac
Nov 20 '18 at 22:18





You guys are the best. Thanks! So obvious I guess, but I realise now that I used angular material in an existing project so didn't have to apply this step. Never again.

– MadMac
Nov 20 '18 at 22:18












1 Answer
1






active

oldest

votes


















1














The comments from @user18994 and @SiddAjmera answered this.



Step 4: Include a theme



Including a theme is required to apply all of the core and theme styles to your application.



To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:



@import "~@angular/material/prebuilt-themes/indigo-pink.css";
If you are not using the Angular CLI, you can include a prebuilt theme via a element in your index.html.



For more information on theming and instructions on how to create a custom theme, see the theming guide.



Source:
https://material.angular.io/guide/getting-started






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402137%2fangular-material-styles-not-being-applied-correctly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The comments from @user18994 and @SiddAjmera answered this.



    Step 4: Include a theme



    Including a theme is required to apply all of the core and theme styles to your application.



    To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:



    @import "~@angular/material/prebuilt-themes/indigo-pink.css";
    If you are not using the Angular CLI, you can include a prebuilt theme via a element in your index.html.



    For more information on theming and instructions on how to create a custom theme, see the theming guide.



    Source:
    https://material.angular.io/guide/getting-started






    share|improve this answer




























      1














      The comments from @user18994 and @SiddAjmera answered this.



      Step 4: Include a theme



      Including a theme is required to apply all of the core and theme styles to your application.



      To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:



      @import "~@angular/material/prebuilt-themes/indigo-pink.css";
      If you are not using the Angular CLI, you can include a prebuilt theme via a element in your index.html.



      For more information on theming and instructions on how to create a custom theme, see the theming guide.



      Source:
      https://material.angular.io/guide/getting-started






      share|improve this answer


























        1












        1








        1







        The comments from @user18994 and @SiddAjmera answered this.



        Step 4: Include a theme



        Including a theme is required to apply all of the core and theme styles to your application.



        To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:



        @import "~@angular/material/prebuilt-themes/indigo-pink.css";
        If you are not using the Angular CLI, you can include a prebuilt theme via a element in your index.html.



        For more information on theming and instructions on how to create a custom theme, see the theming guide.



        Source:
        https://material.angular.io/guide/getting-started






        share|improve this answer













        The comments from @user18994 and @SiddAjmera answered this.



        Step 4: Include a theme



        Including a theme is required to apply all of the core and theme styles to your application.



        To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:



        @import "~@angular/material/prebuilt-themes/indigo-pink.css";
        If you are not using the Angular CLI, you can include a prebuilt theme via a element in your index.html.



        For more information on theming and instructions on how to create a custom theme, see the theming guide.



        Source:
        https://material.angular.io/guide/getting-started







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 22:23









        MadMacMadMac

        367




        367






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402137%2fangular-material-styles-not-being-applied-correctly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]