为什么我的dropdwon添加了一个空格angularjs

时间:2016-10-21 08:49:02

标签: javascript c# angularjs web-services

我从webservice的{​​{1}}获取数据,数据以angularjs格式显示

这是我的js文件

Json

这是我的下拉列表

//getzonebyid
            $http.get('/zone.asmx/zone', {
                params: {
                    log: log,
                    pm: pm,
                    id: $scope.updateparam.Id
                }
            })

            .then(function (response) {
                {
                    $scope.gzone = response.data.zone;
                    console.log(response.data.zone);
                }
            });

我不知道为什么在我的下拉列表顶部有一个额外的空白区域,我只想让我的第一个<select ng-model="uzone" ng-change="locationupd(c)"> <option ng-repeat="l in gzone" value="{{l.jzone}}">{{l.jzone}}</option> </select> 成为来自我的数据库的第一个值但是我被困在额外的空间中通过我的下拉

我alson试过

option

但它对我没有帮助 拜托,伙计们,我现在被困在这一天

Json格式的数据$scope.uzone=$scope.gzone[0].value;

2 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为即使它可能取决于您正在编写的选择标记的方式,让我向您展示一些您可以获得更好知识的示例:

(function(angular) {
  'use strict';
angular.module('staticSelect', [])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.data = {
     singleSelect: null,
     multipleSelect: [],
     option1: 'option-1'
    };

    $scope.forceUnknownOption = function() {
      $scope.data.singleSelect = 'nonsense';
    };
 }]);
})(window.angular);
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example</title>  

  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body ng-app="staticSelect">
  <div ng-controller="ExampleController">
  <form name="myForm">
    <label for="singleSelect"> Single select: </label><br>
    <select name="singleSelect" ng-model="data.singleSelect">
      <option value="option-1">Option 1</option>
      <option value="option-2">Option 2</option>
    </select><br>

    <label for="singleSelect"> Single select with "not selected" option and dynamic option values: </label><br>
    <select name="singleSelect" id="singleSelect" ng-model="data.singleSelect">
      <option value="">---Please select---</option> <!-- not selected / blank option -->
      <option value="{{data.option1}}">Option 1</option> <!-- interpolation -->
      <option value="option-2">Option 2</option>
    </select><br>
    <button ng-click="forceUnknownOption()">Force unknown option</button><br>
    <tt>singleSelect = {{data.singleSelect}}</tt>

    <hr>
    <label for="multipleSelect"> Multiple select: </label><br>
    <select name="multipleSelect" id="multipleSelect" ng-model="data.multipleSelect" multiple>
      <option value="option-1">Option 1</option>
      <option value="option-2">Option 2</option>
      <option value="option-3">Option 3</option>
    </select><br>
    <tt>multipleSelect = {{data.multipleSelect}}</tt><br/>
  </form>
</div>
</body>
</html>

答案 1 :(得分:0)

您的代码存在的问题是,您使用的是ng-model,但没有为其设置默认值

  <select ng-init="selected='South'" ng-model="selected " ng-options="c.jzone as c.jzone for c in result.zone"></select>

<强> DEMO