HelloWorld HelloWorld - 4 months ago 18
AngularJS Question

AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?

Using AngularJS if I set a simple input text box value to something like "bob" below. The value does not display if the

ng-model
attribute is added.

<input type="text"
id="rootFolder"
ng-model="rootFolders"
disabled="disabled"
value="Bob"
size="40"/>


Anyone know of a simple work around to default this input to something and keep the
ng-model
? I tried to use a
ng-bind
with the default value but that seems not to work either.

Answer

That's desired behavior, you should define the model in the controller, not in the view.

<div ng-controller="Main">
  <input type="text" ng-model="rootFolders">
</div>


function Main($scope) {
  $scope.rootFolders = 'bob';
}
Comments