我有布爾屬性爲客戶打電話IsMarried
我想用<select>
標籤波紋管:AngularJS:在NG選項選項設定值
我應該如何改變NG選項,因爲我想要設置1
爲Yes
和0
爲No
的選項。我該怎麼辦?
我有布爾屬性爲客戶打電話IsMarried
我想用<select>
標籤波紋管:AngularJS:在NG選項選項設定值
我應該如何改變NG選項,因爲我想要設置1
爲Yes
和0
爲No
的選項。我該怎麼辦?
上你可以有0
& 1
爲各自的狀態
標記
<select name="isMarried" id="isMarried"
class="form-control" ng-model="customer.isMarried"
ng-options="statue.value as statue.description for statue in maritalStatues">
</select>
代碼
$scope.maritialStatus = [ { value : 1, description : "Yes"}, {value : 0, description : "Unmarried"}];
您還沒有提供很多信息,有關對象,但如果我們的對象數組是這樣的:
$scope.maritialStatus = [ { id : 1, name : "Married"}, {id:2,name: "Unmarried"}]
,那麼你可以寫你的選擇是這樣的:
<label for="singleSelect"> Single select: </label><br>
<select name="repeatSelect" id="repeatSelect" ng-model="customer.isMarried">
<option ng-repeat="status in martialStatus" value="{{status.id}}">{{status.name}}</option>
</select>
嘗試。在您的控制器
$scope.maritalStatues = [{statusKey: 0 , statusTitle : 'Unmarried'},{statusKey: 1 , statusTitle : 'Married'}];
視圖頁面
<select name="isMarried" id="isMarried" class="form-control" ng-model="customer.isMarried" ng-options="status.statusKey as status.statusTitle for status in maritalStatues">
</select>