tb / ng2-nouislider

Angular2 noUiSlider directive
http://tb.github.io/ng2-nouislider/
MIT License
184 stars 114 forks source link

Angular 5.2.1 - slider doesn't show #157

Closed zHaytam closed 6 years ago

zHaytam commented 6 years ago

Hello, I was looking for a good looking slider for my project and I found this one but the slider doesn't show and I'm not sure wheither it's my fault or not.

app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NouisliderModule } from 'ng2-nouislider';
import { AppComponent } from './app.component';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        NouisliderModule
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }

app.component.css:

@import "~nouislider/distribute/nouislider.min.css";
...

app.component.html:

<nouislider [connect]="true" [min]="0" [max]="15" [(ngModel)]="inputSpeedRange"></nouislider>

app.component.ts:

public inputSpeedRange = [4, 80];

kiqq commented 6 years ago

Move @import "~nouislider/distribute/nouislider.min.css"; to styles.css.

zHaytam commented 6 years ago

Thank you, it worked!

zHaytam commented 6 years ago

I changed the inputSpeedRange to public inputSpeed = 20;

The problem is, the inputSpeed doesn't get updated (not like in the demo) and I have to do this little "hack" to make it work: <nouislider [min]="4" [max]="80" [step]="1" [(ngModel)]="inputSpeed" (change)="inputSpeed = $event"></nouislider>

Is this a known issue or am I (again) doing something wrong? Thank you.

kiqq commented 6 years ago

Do you have FormsModule imported in app.module.ts?

zHaytam commented 6 years ago

Perfect, thank you for the help!

Do you mind me asking why does it need FormsModule in this case?

kiqq commented 6 years ago

NgModel directive is a part of FormsModule: https://github.com/angular/angular/blob/master/packages/forms/src/form_providers.ts:

import {InternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES, TEMPLATE_DRIVEN_DIRECTIVES} from './directives';

@NgModule({
  declarations: TEMPLATE_DRIVEN_DIRECTIVES,
  providers: [RadioControlRegistry],
  exports: [InternalFormsSharedModule, TEMPLATE_DRIVEN_DIRECTIVES]
})
export class FormsModule {
}

https://github.com/angular/angular/blob/master/packages/forms/src/directives.ts: export const TEMPLATE_DRIVEN_DIRECTIVES: Type<any>[] = [NgModel, NgModelGroup, NgForm];

zHaytam commented 6 years ago

Oh, got it! Thank you for your time.

arjunkolagatla commented 6 years ago

Hi All,

How to get two handles like attachment? Any help would be appreciated. Thanks screen shot 2018-06-13 at 3 02 10 pm

arjunkolagatla commented 6 years ago

Sorry, I just did figured out by change public inputSpeed = [10,20]; Just that variable name "inputSpeed" is confusion, you can change to range or something else.

Thanks