Hello. There is ng: repeat, created by json (methods), inside it creates a series of radio buttons that are characterized by iteration (method).

Below, I need to create a variable in which the method of the selected radio button will lie, for later use. I sketch a template for clarity.

<li ng:repeat="method in methods"> <label> <input type="radio" ng:model="$parent.deliveryMethod" ng:value="method" /> </label> </li> <table ng:init="myValue = deliveryMethod.price | format"> <tr> <td ng:bind="myValue"></td> </tr> </table> 

I hope the essence is clear. The problem is that, as I understand it, ng: init is triggered before the methods have time to form.

How to be? Thank.

  • Hello. Please show json methods . And also explain in more detail what you need? If you write in the deliveryMethod method value, then it will be there. - Stepan Kasyanenko

1 answer 1

If I understood correctly, then you just need to show the selected element from the methods array in another place.

Check out the jsfiddle example.

 angular.module('ExampleApp', []) .controller('ExampleController', function($scope) { $scope.methods = [{ id: 1, name: "1", price:100 }, { id: 2, name: "2", price:200 }]; $scope.deliveryMethod ={method:null}; $scope.deliveryMethod2 ={myValue:null,method:null}; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <div ng-app="ExampleApp"> <div ng-controller="ExampleController"> <h3> Пример без переменной </h3> <ul> <li ng:repeat="method in methods"> <label> <input type="radio" name="method" ng:model="deliveryMethod.method" ng-value="method" />{{method.name}} </label> </li> </ul> <table> <tr> <td ng:bind="deliveryMethod.method.price | currency"></td> </tr> </table> <h3> Пример с переменной </h3> <ul> <li ng:repeat="method in methods"> <label> <input type="radio" name="method2" ng:model="deliveryMethod2.method" ng-change="deliveryMethod2.myValue = (method.price | currency)" ng-value="method" />{{method.name}} </label> </li> </ul> <table> <tr> <td ng:bind="deliveryMethod2.myValue"></td> </tr> </table> </div> </div>