簡體   English   中英

我可以使用ng-model setter-getter選項轉換模型中變量的值嗎?

[英]Can I use ng-model setter-getter option to transform the value of a variable in the model?

我在angularjsangularjs以下情況:

<select ng-model="value">
    <option ng-repeat="type in types">{{type.description}}</option>
<select>

控制器看起來像:

$scope.value = null;
$scope.types=[{description: "asdf", id:"a"}, {description: "basdf", id:"b"}];

我想設置$ scope.value,而不是與價值type.description ,但其對應的ID值: type.id 但是我仍然想在下拉選擇中顯示說明。

我可以使用ng-model的getterSetter選項完成此操作嗎? 我看了文檔,但並不清楚。

您不需要getterSetter來執行此操作。 您需要的只是ng-options

<select ng-model="value" ng-options="type.id as type.description for type in types">
</select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM