我尝试使用ng-slider npm模块,可在此处找到: https://www.npmjs.com/package/ng-slider
我已经导入了所有必要的JS代码。然后使用它来制作滑块:
<input slider id="sliderID" ng-model="value" name="slider" type="text" options="{from:0,to:100,step:1,smooth:false,skin:'plastic'}"/>
它出现在屏幕上,但它不起作用,因为我在ng-slider.min.js中收到错误。如下:
"Error: e.settings.value is undefined
e.prototype.create@http://lh:5000/javascripts/ng-slider.min.js:6:9226
e.prototype.init@http://lh:5000/javascripts/ng-slider.min.js:6:8818
e@http://lh:5000/javascripts/ng-slider.min.js:6:8300
.link/p@http://lh:5000/javascripts/ng-slider.min.js:6:2268
.link/m@http://lh:5000/javascripts/ng-slider.min.js:6:1420
.link/</<@http://lh:5000/javascripts/ng-slider.min.js:6:2089
timeout/timeoutId<@http://lh:5000/javascripts/angular.js:16299:28
completeOutstandingRequest@http://lh:5000/javascripts/angular.js:4924:7
Browser/self.defer/timeoutId<@http://lh:5000/javascripts/angular.js:5312:7
所以很自然地,我查看了ng-slider.min.js文件,但当然随着它的缩小,它几乎不可能看到什么&#34; e&#34;是为什么它的设定值没有定义。因此,如果有人之前遇到过这个错误,并且知道如何修复它,那将非常感激。
由于 亚当
编辑:html上的两个ID是错误的,现在已经纠正,但原始问题仍然存在。
答案 0 :(得分:0)
我可以看到的主要问题是您的input
有两个 ID。省略其中一个。
<input slider id="sliderID" ng-model="value" name="slider" type="text" options="{from:0,to:100,step:1,smooth:false,skin:'plastic'}"/>
答案 1 :(得分:0)
尝试这种方式:
<input slider id="sliderID" ng-model="value" name="slider" type="text" options="myOptions"/>
在控制器中:
$scope.myOptions = {from: 0, to: 100, step: 1, smooth: false, skin: 'plastic'};
传递options属性时, myOptions
是一个范围而不是常规对象。
PS:并删除第二个ID,因为@Zee说。
编辑:您可能忘记将$scope.value
添加到控制器。