2

상황 요소를 포장 :

나는 그것이 템플릿에 요소의 랩하는 속성 지시자가있다.AngularJS와 : 각도 속성 지시자와 함께 사용자 지정 서식에

app.directive("myCustomInput", function(){ 
    return{ 
    restrict: "A", 
    replace: true, 
    scope:{}, 
    transclude: "element", 
    template: "<div class='input-wrap'>"+ 
    "<div ng-transclude></div>"+ 
    "<i class='glyphicon glyphicon-chevron-down'></i>"+ 
    "</div>" 
    } 
}); 

그리고처럼 사용 : 여기있다

<input my-custom-input ng-model="data.input" type="text" /> 

문제 :

ng-model
여기
plunker

+1

재미있는 것은 이것이 당신이 [다른 질문] 제공 대답이었다 (http://stackoverflow.com/questions/25295882/angular-attribute-directive-that입니다 -wraps-its-element/27648516 # 27648516)? :) – PSL

+0

:)) 정확하게! 나는 내 자신의 문제가 발생할 때까지 실제로 그 대답에서 말한 것을 사용하고있었습니다! –

답변

1

당신은 않을 수 있습니다 작동하지 않습니다 가능성이있는 버그가 발생했습니다. 우선 순위 및 지시 처리 순서 문제입니다. 지시문을 ng 모델보다 우선 순위를 설정하십시오. 1.2 v를 사용하는 경우 ng-model은 기본 우선 순위가 0이고 1.3 버전 ng-model은 우선 순위가 1입니다. 따라서 지시문을 렌더링하기 전에 입력을 처리하기 전에 지시문과 변환이 발생하도록 지시문이 ng 모델보다 우선 순위가 높아야합니다. 난 그냥 눈치

.directive("myCustomInput", function(){ 
    return{ 
    restrict: "A", 
    replace: true, 
    scope:{}, 
    priority: 1, //Here set the priority 
    transclude: "element", 
    template: "<div class='input-wrap'>"+ 
    "<div ng-transclude></div>"+ 
    "<i class='glyphicon glyphicon-chevron-down'></i>"+ 
    "</div>" 
    } 
}); 

Demo

+0

감사합니다. "버그"에 대해 더 설명해 주시겠습니까? –