Search code examples
htmlangularjsintel-xdk

AngularJS Form Selecet values


Hi I'm starting to work with AngularJS and Intel XDK trying to make a form and send data by AJAX with JSON. I'm trying first of all to show the information that I get from the input and comboBox but I have some trouble with comboBox. I followed the guides from w3schools.com but I couldn't make it work.

<div ng-app="myApp" ng-controller="myCtrl">
    <label class="item item-input item-select">
        <div class="input-label">
            Tipo de Sangre
        </div>
        <select ng-model="selectedName" ng-options="x for x in names"></select>
    </label>
</div>

<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.region = ["Región de Los Ríos"];
        $scope.names = ["A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-"];
        $scope.comuna = ["Corral", "Lanco", "Los Lagos", "Máfil", "Mariquina", "Paillaco", "Panguipulli", "Valdivia", "Futrono", "La Unión", "  Lago Ranco", "Río Bueno" ];
    });
</script>

<h3>Hello {{event.rut + " " + event.nombre + " " + event.apellido + " " + event.telefono + " " + selectedRegion + " " + selectedComuna + " " + selectedName}}</h3>

Solution

  • Here I only initiated the variable as empty:

    app.controller('MainCtrl', function($scope) {
        $scope.name = 'World';
        $scope.selectedName = '';
        $scope.region = ["Región de Los Ríos"];
        $scope.names = ["A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-"];
        $scope.comuna = ["Corral", "Lanco", "Los Lagos", "Máfil", "Mariquina", "Paillaco", "Panguipulli", "Valdivia", "Futrono", "La Unión", "  Lago Ranco", "Río Bueno" ];
    });
    

    Here is the plunker https://plnkr.co/edit/WlqV02JsA8z43j33wuZ2?p=preview

    Your h3 tag is outside the controller scope so its not printing anything. include the h3 tag inside the div :

    <div ng-app="myApp" ng-controller="myCtrl">
        <label class="item item-input item-select">
            <div class="input-label">
                Tipo de Sangre
            </div>
            <select ng-model="selectedName" ng-options="x for x in names"></select>
        </label>
    <h3>Hello {{event.rut + " " + event.nombre + " " + event.apellido + " " + event.telefono + " " + selectedRegion + " " + selectedComuna + " " + selectedName}}</h3>
    </div>
    

    Hope it helps