我有一个要重构的 ng-switch 语句。它看起来像这样:
<div ng-switch on="property.type">
<input type="text" ng-switch-when="string" ng-model="property.value" placeholder="Property value">
<select ng-switch-when="bool" ng-model="property.value" ng-options="value for value in [true,false]" placeholder="Property value"></select>
<input type="number" ng-switch-when="int" ng-model="property.value" placeholder="Property value">
<input type="text" ng-switch-default ng-model="property.value" placeholder="Property value">
</div>
您会注意到ng-model
和placeholder
选项在所有情况下都是相同的。我的问题是:我可以以某种方式重构它以使这些选项只写一次吗?
谢谢!乌里