[英]Default input number value
I'm new to angularJS and I've just created a simple input box where I want a default value. 我是angularJS的新手,我刚刚创建了一个简单的输入框,需要默认值。
Here's the input: 这是输入:
<input id="fieldWidth" min="10" type="number" value="10" ng-model="set.width">
However, the value doesn't show as default. 但是,该值不显示为默认值。
When I try to set it though the scope in the controller 当我尝试通过控制器的范围进行设置时
$scope.set.width = "10";
it says 它说
"Cannot set property 'width' of undefined"
What am I missing? 我想念什么?
If you haven't already... you should set $scope.set before trying to set it's child: 如果您还没有...应该在尝试设置$ scope.set为子级之前设置它:
$scope.set = {width:10};
or 要么
$scope.set = {};
$scope.set.width = 10;
or you can do without the set object if you don't have other values you are associating with it. 或者,如果没有其他值,则可以不使用set对象。
$scope.width = 10;
<input id="fieldWidth" min="10" type="number" ng-model="width">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.