2014-10-12 2 views
0

리팩토링하고 싶은 ng-switch 문이 있습니다. 그것은 다음과 같습니다공유 옵션이있는 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-modelplaceholder 옵션은 모든 경우에 동일하다는 것을 알 수 있습니다. 내 질문은 : 나는 어떻게 든이 옵션을 한 번만 작성하도록 리펙토링 할 수 있습니까?

감사합니다. 완전히 모든 중복을 피하기 위해 리팩토링하지 않지만 열린

답변

0

, 당신은 입력 태그를 결합하여 조금 줄일 수 있습니다 : 이것이 내가 프로젝트라면

<div ng-switch on="property.type"> 
    <select ng-switch-when="bool" ng-model="property.value" ng-options="value for value in [true,false]" placeholder="Property value"></select> 
    <input type="{{property.type == 'int' ? 'number' : 'string'}}" ng-switch-default ng-model="property.value" placeholder="Property value"> 
</div> 

http://plnkr.co/edit/FybDC1I4U7rSC6GZJ3az

에서 볼 수있다 계속 작업하고 있었는데, 나는 그것이 더 이상 리펙토링하지 않을 것이고, 소량의 반복 된 마크 업을 남기고, 명확한 일을 계속하기를 원한다.