angular 2 nouislider: How to recreate the slider?

寵の児 提交于 2019-12-12 04:12:02

问题


I need to change the number of handles on a slider. When googling it says I need to destroy and create the slider again.

Now it says here: Updating and reading slider options that:

To update any other option, destroy the slider using slider.noUiSlider.destroy() and create a new one. Note that events are not unbound when destroying a slider.

I was able to destroy the slider:

@ViewChild('slider') slider;

destroySlider() {
    this.slider.slider.destroy();
}

but I can't seem to find how to create the slider in angular.

Any help is appreciated.


回答1:


You can wrap slider in EmbeddedView via *ngIf

component.html

<button (click)="reCreate()">Recreate slider</button>

<nouislider *ngIf="flag" #slider [config]="someKeyboardConfig"></nouislider>

and then reCreate function could look like:

component.ts

flag = true;

reCreate() {
  this.slider.slider.destroy();
  this.flag = false;
  this.cdRef.detectChanges();
  this.flag = true;
}

Plunker Example



来源:https://stackoverflow.com/questions/45526114/angular-2-nouislider-how-to-recreate-the-slider

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