AngularJS 表单选择值

AngularJS Form Selecet values

您好,我开始使用 AngularJS 和 Intel XDK 尝试制作表格并通过 AJAX 和 JSON 发送数据。我首先尝试显示我从输入和组合框获得的信息,但我在使用组合框时遇到了一些麻烦。我遵循了 w3schools.com 中的指南,但无法正常工作。

<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>

这里我只初始化了变量为空:

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" ];
});

这是个笨蛋 https://plnkr.co/edit/WlqV02JsA8z43j33wuZ2?p=preview

您的 h3 标签在控制器范围之外,因此它不会打印任何内容。在 div :

中包含 h3 标签
<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>

希望对您有所帮助