简体   繁体   中英

Edit Angular material mat-form-field in custom.sass

I try to change to style of a mat-form-field. Because ::ng-deep is getting deprecated I use custom.sass files to change the style. But with this code only mat-form-field changes but not the elements inside.

.mat-form-field
    background-color: #ffffff
    border: solid 0.9px #001757
    border-radius: 6.9px
    width: 90px
    height: 40px

    .mat-form-field-wrapper
        .mat-form-field-flex
            width: 22%
            .mat-form-field-infix
                padding: 0 0

        .mat-form-field-underline
            display: none

In this example I want to change the position of the input and remove the underline, but nothing except the border and the color of the mat-form-field changes.

I found the problem: I forgot to add the import statement of my material-import.sass in the styles.sass. Now it's working!

You have to move those styles from your component.scss to the styles.scss file. That's the only way to target nested elements within an Angular component without using deprecated selectors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM