Joe82 Joe82 - 8 days ago 5
AngularJS Question

AngularJS - Change scope with one of the iterations of a ng-repeat

I have a project with Angular where I don't want to use a select element with ng-options, so I made up a list with different options in order to select one of them.

<div class="countrylist">
<ul>
<li ng-repeat="c in shippingCountry"><p>{{c.name}}</p></li>
</ul>
</div>


So the option selected would modify another element where the chosen option would be displayed.

<div>
<ul>
<li>{{selectedCountry}}</li>
</ul>
</div>


In order to do that, I would need to pass the data from the chosen option of the first element into the 2nd one. I have tried doing something like this

<li ng-repeat="c in shippingCountry" ng-click="selectedCountry = {{c}}"><p>{{c.name}}</p></li>


with no success.

You can check the plunker here Thanks in advance

Answer

I suggest you to use a function over there like this in the DEMO

<li ng-repeat="c in shippingCountry" ng-click="Click(c)"><p>{{c.name}}</p></li>

Having this method in your controller

$scope.Click=function (c)  
 {
   $scope.select=c;

 }
Comments