简体   繁体   中英

Default input number value

I'm new to angularJS and I've just created a simple input box where I want a default value.

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 = {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.

$scope.width = 10;

<input id="fieldWidth" min="10" type="number" ng-model="width">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM