2016-03-02 42 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"]; 
});