2016-03-02 51 views
0

我想创建两个角度的选择框,但只有第一个是appering,任何帮助! HTML:两个角度选择框,只出现一个

<div><p><span id="countryLocale"> 
CountryName<select ng-model="selectedCountry" ng-options="x for x in names"> 
</span> 
</p> 
<p><span id="languageLocale"> 
Language<select ng-model="selectedLang" ng-options="x for x in langLocale"> 
</span> 
</p> 
</div> 

控制器: 我有限定在控制器两个静态阵列 $ scope.names = [ “印”, “法国”]; $ scope.langLocale = [“English”,“French”];

回答

3

关闭选择标签。

<div><p><span id="countryLocale"> 
CountryName <select ng-model="selectedCountry" ng-options="x for x in names" ></select> 
</span> 
</p> 
<p><span id="languageLocale"> 
Language<select ng-model="selectedLang" ng-options="x for x in langLocale" ></select> 
</span> 
</p> 
</div> 

其他注意事项 虽然我一直在寻找回答这个问题,我试过下面的代码没有工作

<select ng-model="selectedLang" ng-options="x for x in langLocale" /> 
<select ng-model="selectedLang" ng-options="x for x in langLocale" /> 

这是因为在HTML 5 <foo />等于<foo>但不<foo></foo>

因此,选择必须像<select></select>,但不能用于<select />

0

你失踪了select的结束标记元件。请使用像Visual Studio等编辑器,它会突出显示开发过程中的代码错误。

请参阅工作演示here

HTML:

<div ng-app="app" ng-controller="test"> 
    <div> 
     <p> 
      <span id="countryLocale"> 
       CountryName<select ng-model="selectedCountry" ng-options="x for x in names"></select> 
      </span> 
     </p> 
     <p> 
      <span id="languageLocale"> 
       Language<select ng-model="selectedLang" ng-options="x for x in langLocale"></select> 
      </span> 
     </p> 
    </div> 
</div> 

JS:

var app = angular.module('app', []); 

app.controller('test', function ($scope) { 
    $scope.names = ["INDIA", "France"]; 
    $scope.langLocale = ["English", "French"]; 
});