how to fill a directive fact combo, from angular


I want in a dynamic form to be able to set a value to a Combo (Select), however when the dynamic controls are rendered, the combo, which is a directive, does not preload the value that is sent to it.

I would like to know how to resolve this issue. The code is below and also reference the example in Plunk . When loading the page or adding new rows, the combo does not leave the value that comes in the JSON selected.


<html ng-app="shanidkvApp">
    <link rel="stylesheet" href="style.css" />
    <script data-require="[email protected]" src="" data-semver="1.2.28"></script>
    <script src="app.js"></script>
    <!--[if IE]>
    <script src=""></script>

    <div class="container">
        <div class="row">
            <h3>AngularJS Dynamic Form Fields</h3>
            <hr />
            <div ng-app="angularjs-starter" ng-controller="MainCtrl">
                <fieldset data-ng-repeat="choice in choices">
                    <select ng-model="">
                        <option value="Mobile" >Mobile</option>
                        <option value="Office" >Office</option>
                        <option value="Home" >Home</option> 

                    <sel caremonda="choice.res" opciones="paises"></sel>
                    <input type="text"  value="{{choice.res}}">
                    <input type="{{choice.type}}" ng-model="" name="" placeholder="Enter mobile number">
                    <button class="remove" ng-show="$last" ng-click="removeChoice()">-</button>
                <button class="addfields" ng-click="addNewChoice()">Add fields</button>
                <button class="addfields" ng-click="mostrar()">Mostrar</button>

                <div id="choicesDisplay">
                    {{ choices }}

                <select ng-model="multipleSelect">
                    <option value="var1">Option 1</option>
                    <option value="var2">Option 2</option>
                    <option value="var3">Option 3</option>
                <tt>multipleSelect = {{multipleSelect}}</tt><br />

asked by Oscar Alonso Rueda Ruiz 23.02.2017 в 00:38

1 answer


Use the ngSelected directive in the select options, this directive is guided by an expression to mark an option as selected :

<option ng-repeat="facility in countries" value="{{facility.value}}" ng-selected="facility.value == leValor">{{}}</option>
answered by 26.02.2017 / 02:33