设置Dialog继承主题更好的方式

来源:2-10 对话框的使用

LongingTT

2017-11-24

只要将项目代码稍作修改,就能完美支持Dialog自动继承主题样式。

  1. 移除mat-sidenav-container上的class设置[class.my-app-theme]="myapptheme".

  2. 添加hostbinding修饰将变量myapptheme绑定到host元素上,具体代码如下

    import { Component,HostBinding } from '@angular/core';

    import { ElementDef } from '@angular/core/src/view';

    @Component({

    selector: 'app-root',

    templateUrl: './app.component.html',

    styleUrls: ['./app.component.scss']

    })

    export class AppComponent {

    @HostBinding('class.my-app-theme') myapptheme:boolean = false;

    switchTheme(value)

    {this.myapptheme=value;}

    }

  3. 修改theme.scss

    .my-app-theme,.my-app-theme~div{

    @include angular-material-theme($my-app-theme);

    }

写回答

2回答

接灰的电子产品

2017-11-24

往后面看吧,其实不用这样设置的。但能想到这一层非常不错的

0
0

LongingTT

提问者

2017-11-24

已解决,具体方式见问题描述,请指正

0
0

Angular打造企业级协作平台,让你在Angular领域中出类拔萃

全网首个介绍官方 Material 组件库用法与 Redux 在 Angular 中的应用

998 学习 · 536 问题

查看课程