andres.gtz
andres.gtz

Reputation: 634

AngularJS - Why ng-value overrides value attribute and how to avoid it?

So, I have the following code:

<input ng-model="refreshedByExample" type="text">
<select ng-model="example" ng-change="refreshedByExample = example">
    <option value="1" ng-value="valueForRefreshedByExample1">1</option>
    <option value="2" ng-value="valueForRefreshedByExample2">2</option>
    <option value="3" ng-value="valueForRefreshedByExample3">3</option>
</select>

The value of the value's attribute is different than the value in ng-value. But, somehow, it is overrides and the value attribute gets the same value than ng-value. I get something like this:

<input ng-model="refreshedByExample" type="text">
<select ng-model="example" ng-change="refreshedByExample = example">
    <option value="valueForRefreshedByExample1" ng-value="valueForRefreshedByExample1">1</option>
    <option value="valueForRefreshedByExample2" ng-value="valueForRefreshedByExample2">2</option>
    <option value="valueForRefreshedByExample3" ng-value="valueForRefreshedByExample3">3</option>
</select>

Is there a way to prevent this? I need to have on the value attribute a different value than in ng-value.

Any ideas? Thanks everyone.

Upvotes: 0

Views: 247

Answers (0)

Related Questions