我无法获得初始化值的输入
查看:
<form ng-submit="changeDistance(form)" id="form">
<input min="1" max="50" ng-model="form.distance" type="range">
<button type="submit" >
Done
</button>
</form>
控制器:
$scope.form = {};
$scope.form.distance = $localStorage.distance;
$scope.changeDistance = function(form){
$localStorage.distance = form.distance;
}
这样可行,但问题是无法提交值:
View:
<form ng-submit="changeDistance(form)" id="form">
<input min="1" max="50" ng-model="distance" type="range">
<button type="submit" >
Done
</button>
</form>
Controller:
$scope.distance = $localStorage.distance;
$scope.changeDistance = function(form){
console.log(form.distance)//cannot read
}
答案 0 :(得分:0)
这是Angular 1.2的确认错误。有关详细信息,请参阅Github bug report。
答案 1 :(得分:0)
尝试使用角度为1.3.14及以上的上述代码(使用ng-model="form.distance"
的地方)。