I know this issue has been going on since 2018 and there are a LOT of posts and different solutions, however none have worked for me.
I have created a new Angular 14 project, removed the start template, added capacitor and material. I added a slider from the first Material example . If I run the project via:
ng serve --open
It works as expected in the browser. Then I do:
ng build
npx cap sync
npx cap run android
to see the slider in Android Studio in an emulator. You can click and cause the slider to move, but you cannot "slide" the slider, which is the point. It "works" something like this:
During the troubleshooting process, I have reviewed many solutions. The most important I think are:
I apologize in advance that I cannot "post a minimum repo" at this time but this is pretty easy to create:
It seems lots of people are still having this problem. In 2022, 4 years into this problem, is there a "right way" to use the slider to make it actually do the job or is it best to abandon material in this case?
I am by no means an expert at Angular so it's very possible it's my mistake. I would prefer to use Material if possible, but the slider is pretty fickle it seems.
My html:
<mat-slider aria-label="unit(s)"></mat-slider>
My SCSS:
mat-slider {
width: 300px;}
app.module.ts (my component is MatchAnalysisComponent)
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { MatchAnalysisComponent } from './match-analysis/match-analysis.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MatSliderModule } from '@angular/material/slider'; @NgModule({ declarations: [ AppComponent, MatchAnalysisComponent ], imports: [ BrowserModule, AppRoutingModule, BrowserAnimationsModule, MatSliderModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
The best solution for me was to abandon the mat-slider and use the html input with type range. The tradeoff is the html range input cannot be easily styled. At least it works as expected and works well with Angular versus the material slider which is unusable on a mobile device.
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.