Disable globally ripple effect angular 2 app

非 Y 不嫁゛ 提交于 2019-12-10 14:34:23

问题


I have an app which is using material 2, i would like to globally disable the ripple effect for all components or directives that use it. I don't want to do this overriding css classes. One thing that comes in my mind is creating a directive which can extend MdRipple and then override its properties, not sure tho. I would like to know your opinion or example how this can be done in the right way.


回答1:


Import ripple specific token and interface

import { MD_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions } from '@angular/material';

then create config

const globalRippleConfig: RippleGlobalOptions = {disabled: true};

then add new provider to your main NgModule

providers: [{provide: MD_RIPPLE_GLOBAL_OPTIONS, useValue: globalRippleConfig}]

With MD_RIPPLE_GLOBAL_OPTIONS you can also configure ripple size, color, animation speed




回答2:


The provider changed in recent versions. You need to use MAT_RIPPLE_GLOBAL_OPTIONS not MD_RIPPLE_GLOBAL_OPTIONS.

Update your AppModule.ts

...

import {  MAT_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions } from '@angular/material';

const globalRippleConfig: RippleGlobalOptions = {
  disabled: true
};

@NgModule({
  imports:      [
    ...
    ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
  providers: [{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useValue:     globalRippleConfig}]
})
export class AppModule { }



回答3:


As a slightly simpler alternative, if you only want to disable the ripple effect completely, you don't need a const globalRippleConfig, you can just put it inline.

So the import looks like this:

// maybe '@angular/material' below depending on your material version
import {MAT_RIPPLE_GLOBAL_OPTIONS} from '@angular/material/core';

and in NgModule:

providers: [
    { provide: MAT_RIPPLE_GLOBAL_OPTIONS, useValue: {disabled:true} },
    // and any other providers here
],


来源:https://stackoverflow.com/questions/43078270/disable-globally-ripple-effect-angular-2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!