user3174311
user3174311

Reputation: 1993

AngularJS bind elements inside a loop

I have this loop to show a list of input text

<div ng-repeat="country in countries">
  <input ng-blur="saveCountryName(country)" type="text" value="{{country.name}}">
</div>

in my controller

$scope.saveCountryName = (country) => {
  console.log(country);
}

country is filled with the original value, how can I get the modified value?

Upvotes: 1

Views: 50

Answers (1)

Shevchenko Viktor
Shevchenko Viktor

Reputation: 5396

In AngularJS you have all power of two-way data binding, no need to use a special function (saveCountryName).

<div ng-repeat="country in countries">
  <input type="text" ng-model="country.name" ng-model-options="{ updateOn: 'blur'}" />
</div>

Upvotes: 1

Related Questions