0

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?

1
  • 2
    you don't need to set the value attribute in your input field. just in your controller do this: $scope.set = { width: 10 }; Commented Sep 19, 2014 at 18:50

1 Answer 1

2

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">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.