배열을 사용하여 ng-options
으로 목록을 채우고 선택한 항목에 바인딩 된 속성이 있습니다. 배열을 삭제 한 후에 바운드 변수 myObject.selectedItem
은 마지막으로 선택한 항목의 값을 유지합니다.배열을 지운 후에 ng-options bound 변수가 업데이트되지 않습니다.
HTML :
<select ng-model="myObject.selectedItem" ng-options="item.Id as item.Name for item in myArrayList | orderBy:'Id'" required>
<option value="">Select something</option>
</select>
JS :
$scope.myArrayList = [ { Id: 1, Name: "Item 1" }, { Id: 2, Name: "Item 2" } ];
$scope.myObject = { selectedItem: null };
... 항목이 선택한 후 :
$scope.myArrayList.length = 0; // Clears the array
console.log($scope.myObject.selectedItem); // Prints: 2
을이 정상적인 행동인가?