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"

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.


Hi you can try below methods with initialize of model.

Here you can initialize ng-model of textbox two way

- With use of ng-init

- With use of $scope in js

The issue is that you have to set the ng-model to the parent element to where you want to set the ng-value/value . As mentioned by Angular:

It is mainly used on input[radio] and option elements, so that when the element is selected, the ngModel of that element (or its select parent element) is set to the bound value.

Eg:This is an executed code :

By : sg28

This video can help you solving your question :)
By: admin