我有一个滑动条,希望它的抓取器从左侧开始。
这是我尝试做的,但它不起作用。
<input type="range" id="{{'sa' + q.id}}" value="0" min="0" max="10" ng-model="q.answer" style="clear:both;"/><span >{{q.answer}}</span>
如您所见,我将该 slider 的值设置为 0,但夹具仍显示在其中间。
你有什么线索吗?
更新
我尝试删除 ng-model="q.answer"并发现问题已解决。但我确实需要 ng-model 来进行数据绑定(bind)。
你有什么线索可以阻止这种情况发生吗?
更新 2
我实际上有一个问题列表来添加属性“answer”,并将其值设置为 0。 这是代码。
$http.get("http://my.azurewebsites.net/api/Questions").success(function (data) {
$scope.questions = data;
angular.forEach($scope.questions, function (value, key) {
console.log(this);
// how to write the code to add an attribute "answer" to the question object and set its value to 0?
});
更新 3:解决方案
我发现问题是由 q.answer 的默认值引起的,因此更改了这个值,我是这样做的。
$scope.questions[key].answer = 0;
感谢您的输入:)
最佳答案
您可能为范围模型 q.answer
分配了一个值。如 fiddle 中所示,将值 0 分配给模型可以解决问题。
$scope.q = {
answer: 3, // answer has an initial value
start: 0 //set to 0 like this
};
关于javascript - 错误地使用 ng-model 会使 slider 从中间开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25277432/