Can't drag md-slider
Bug, feature request, or proposal:
Looks like a bug, but it could be user error (I'm new to Material)
What is the expected behavior?
Should be able to drag on md-slider
What is the current behavior?
Drag doesn't work, though click on slider does set the value
What are the steps to reproduce?
Please check out http://ravinutala.com/d/index.html for an example with just the slider
What is the use-case or motivation for changing an existing behavior?
Just want the correct behavior, not asking for any changes
Which versions of Angular, Material, OS, browsers are affected?
Angular 4.0.3, Material 2.0.0-beta.3, Windows 10, Chrome/FF (only tested on these two)
Is there anything else we should know?
You need to import MaterialModule after either BrowserAnimationsModule or BrowserModule (probably just best to put it after both).
Unfortunately, I couldn't tell you why
I'm getting this issue too. I have tried your suggestion @willshowell but it still doesn't work. It also advises that MaterialModule is now deprecated. I've tried importing the MdSliderModule in the same way though, after BrowserModule and BrowserAnimationsModule, to no avail.
I can't help but think this is something to do with hammerjs, but I'm sure I have followed the Getting Started guide properly.
A little stumped... :/
@stevedeighton Can you provide a bare-minimum repo?
Thanks a lot, @willshowell, that was it: I just had to move MaterialModule after BrowserAnimationsModule (and before BrowserModule, FYI). @stevedeighton, did you change the order in the imports array of @NgModule?
@allurefx yep I did that, I'll have another play later tonight with it and provide a demo if I'm still struggling Thanks @willshowell :D
Aha, found it. I was running angular 4.0.0 still. Upgraded to 4.0.3 and its working now 👍
My guess is that hammerjs isn't loaded yet when the angular app is bootstrapped.
@jelbourn Is there anything we can do to improve this? (e.g. autodetect when hammerjs loads or provide a way for users to trigger it to recheck).
@mmalerba I pulled up the repro and found that Hammer is loaded here at bootstrap. The problem is that it's using the default gesture config rather than the one from material. Haven't figured out why yet.
@allurefx what does your app module (that you're bootstrapping) look like?
Oh, reading the whole thread now I see. If BrowserModule is added after MaterialModule, its gesture config overrides the one slider needs. Wonder if there's anything we can do about tnat.
@jelbourn, the problem appears to be with importing MaterialModule before BrowserAnimationsModule; BrowserModule location doesn't appear to matter. E.g.,
Below one does NOT work imports: [MaterialModule, BrowserAnimationsModule, BrowserModule, HttpModule]
Below ones both work imports: [BrowserAnimationsModule, MaterialModule, BrowserModule, HttpModule] imports: [BrowserAnimationsModule, BrowserModule, MaterialModule, HttpModule]
Looked into it a bit, and unfortunately there's no mechanism for our modules to effectively say "My provider is more important than your provider" (and also no way to change BrowserModule so that it can say that it's less important).
Best we can do for now is to document that the order matters; sent #4291 for this
Hi, I just wanted to point out that I found out another weird behavior.
In order to make md-slider work together with hammerjs inside a lazy loaded module, I have to import MdSliderModule both in the main App.module and in the Lazy.module. This is a wasteful import since I only use MdSliderModule inside the LazyModule.
@iliketomatoes could you please open a separate issue for this with minimal repro
@iliketomatoes dude you are a life saver! I've spent all day trying to figure out why the md-slider would work with ng serve and not when built with ng build.
I had this problem because i forgot to import 'hammerjs'; in the app's root module, I also upgraded angular with
npm i @angular/common@latest @angular/compiler@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest typescript@latest --S -E
then npm i @angular/compiler-cli@latest --D -E
and it was solved
The import order solution never worked for me, though it does seem to be related to something overriding Hammer gestures. I was able to get it working with the following in app module.
import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { GestureConfig, MaterialModule } from '@angular/material';
// Angular material has a bug with the import order of browserModule and angular material which causes Hammger gestures to get overridden.
@NgModule({
providers: [
{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }
]
});
My issue was due to missing hammerjs. Docs note that hammerjs is required for the slider gesters
npm install hammerjs --save
I have the same problem. I've configured hammer to allow vertical scroll on pan section:
export class MyHammerConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
let mc = new Hammer(element, {
touchAction: "pan-y",
});
return mc;
}
}
and now slider doesn't drag fine. If i remove this settings everything works fine. Maybe it overwrites something?
Same problem here. I never needed to import MaterialModule at all. That threw me off at first reading through this thread. I followed the directions in the accepted answer here and the animation worked. (I missed in the docs where hammerjs must be running on the page).