Javascript 如何在angularjs dropbox中设置默认值

Javascript 如何在angularjs dropbox中设置默认值,javascript,angularjs,Javascript,Angularjs,我在做我的angularjs项目。 我选择了下拉列表元素: <select ng-model="register.countryId" ng-options="country.id as country.name for country in register.countries"> <option value = -1 selected>All items</option> </select>

我在做我的angularjs项目。 我选择了下拉列表元素:

<select ng-model="register.countryId" 
        ng-options="country.id as country.name for country in register.countries">
<option value = -1 selected>All items</option>
            </select>
      $scope.register.countries = [{
          id: "1",
          name: "India"
      }, {
          id: "2",
          name: "USA"
      }, {
          id: "3",
          name: "UK"
      }, {
          id: "4",
          name: "Nepal"
      }];
这是

如何设置此默认值:

<option value = -1 selected>All items</option>
所有项目

您必须使用该默认值设置模型,angularjs将显示默认选中的选项。在控制器中:

  $scope.register.countries = [{
      id: "1",
      name: "India"
  }, {
      id: "2",
      name: "USA"
  }, {
      id: "3",
      name: "UK"
  }, {
      id: "4",
      name: "Nepal"
  }];

  // Here you set your model's value
  $scope.register.countryId = $scope.register.countries[0].id;// 0 is index and will be replaced by index of default value in the array

  // This also works fine. And show selected option is india
  $scope.register.countryId = "1";

但我需要设置默认值,不在国家/地区数组内。您的意思是一开始的选项为“选择国家/地区”,对吗?