2014-07-15 6 views
0

select 메뉴를 만들려면 다음과 같은 마크 업이 있습니다.각도로 선택 태그의 첫 번째 요소를 표시하는 방법은 무엇입니까?

내 모델 devices에는 3 개의 개체 (예 : pc1, pc2, pc3)가 포함되어 있습니다.

select이 렌더링되면 빈 값을 가진 목록 (축소됨)을 볼 수 있습니다. 목록을 확장하면 빈 줄이 첫 번째 객체로 표시되고 내 객체 3 개가 표시됩니다.

제 질문은 기본적으로 첫 번째 요소를 표시하는 방법은 무엇입니까?

<select data-ng-model="devices" 
       name="devices" 
       data-ng-required="true" 
       data-ng-options="device.name for device in devices"></select> 

편집 :

html로 각도에 의해 방출 당신은 devices 배열 ng-model에 대한 동일한에 대한 동일한 이름을 넣을 수 없습니다

<option value="?" selected="selected"></option> 
<option value="0">pc1</option> 
<option value="1">pc2</option> 
<option value="2">pc3</option> 
+0

http://stackoverflow.com/questions/12654631/ why-does-angles-are-empty-option-in-select – GibboK

+0

가능한 중복의 [anglejs에서 선택 상자의 기본값을 설정하는 방법] (h ttp : //stackoverflow.com/questions/18380951/how-do-i-set-default-value-of-select-box-in-angularjs) – GillesC

답변

1

입니다.

<select 
    data-ng-model="selectedDevice" 
    name="devices" 
    data-ng-required="true" 
    data-ng-options="device.name for device in devices"> 
</select> 

JS : ng-modelselectedDevice

HTML을 말하고 있다고 가정하자 사용 다른 이름

$scope.devices = [ 
    { name: "pc1" }, 
    { name: "pc2" }, 
    { name: "pc3" } 
]; 

$scope.selectedDevice = $scope.devices[0]; 

DEMO : 어쩌면 관련 http://jsfiddle.net/GFF6P/