0
사용자 지정 지시문을 작성하여 드롭 다운 요소를 생성합니다. 격리 된 범위를 사용하면 컴파일 함수는 템플릿을 변환하지 않습니다.격리 된 범위를 사용할 때 각도 지시문 템플릿 변환
주로 지시문에서 제공되는 select 요소의 ng-options를 변경하고 있습니다. 격리 된 범위에서 어떻게 동일한 결과를 얻을 수 있습니까?
myApp.directive('helloWorld', function() {
return {
restrict: 'E',
replace: true,
scope: {
id:'@',
label:'@'
},
template: '<div class="control-group">' +
' <label for="{{id}}" class="control-label">{{label}}</label>' +
' <div class="controls">' +
' <select id="{{id}}" class="medium m-wrap">' +
' </select>' +
' </div>' +
'</div>',
},
compile:function(tElement, tAttrs, transclude){
var opts = tAttrs.textField
?'item.' + tAttrs.textField + (tAttrs.groupBy ? ' group by item.' + tAttrs.groupBy : '') + ' for item in ' + tAttrs.itemSource
:'item for item in ' + tAttrs.itemSource;
tElement.find('select').attr('ng-options',opts);
}
});
내가 컨트롤러에 제안한대로 추가했지만 여전히 작동하지 않습니다. – Syam
아니요, 지시문입니다! – Fresheyeball
예, 지시문 컨트롤러에 있습니다. – Syam