2014-09-22 1 views
5

범위에 객체 배열이 있으며 아래에있는 드롭 다운 컨트롤에 나열합니다.AngularJS ng-options는 선택한 항목을 객체로 가져옵니다.

<select ng-model="selectedItem" ng-options="product.ID as product.Name for product in products"> 
    <option value="">Please select a product...</option> 
</select> 

나는 또한 내가 내 페이지의 콘텐츠를 manupulate 수 있도록 개체의 다른 속성에 도달하는 객체로되어 selectedItem 싶어. 예를 들어;

<a ng-show="selectedItem.isAvailable">Buy Now!</a> 

아무도 도와 줄 수 있습니까? 고맙습니다.

답변

7

ng-options에서 select as 부분을 제거하면 product이 ngModel이됩니다 (selectedItem).

시도 : -

<select ng-model="selectedItem" ng-options="product.Name for product in products track by product.id"> 
    <option value="">Please select a product...</option> 
</select> 

현재 구문 selectproduct.ID입니다 select as label for value in array, 그래서 당신은 그냥 label for value in array

+1

로 변경하지만 것이 아니 내가하여 트랙을 사용할 때 선택에서 선택한 기본 컬렉션의 id (참조) 만 저장하기 때문에 as의 경우입니다. 그래서 거기에 어떤 해결책이 있습니까? – Dau

+0

tks .. 나를 구해줘. –

관련 문제