-2
속성이 조건부로 요소에 추가되었지만 아무런 해결책도 얻지 못하면 지시문을 호출하려고합니다. HTML조건부로 추가 된 속성에 대한 호출 지시문
<input type="text" max-length="{{max_length}}" myElement/>
다음
는 지시자에게
App.directive('maxlengthCounter', function($compile, $parse) {
return {
require : 'ngModel',
scope : {},
link : function(scope, element, attrs, ngModel) {
var maxLength = parseInt(attrs.maxLength);
if (maxLength) {
element.bind("keyup", function() {
var value = element[0].value;
element.val(value.substr(0, maxLength));
});
}
}
};
});
조건부
App.directive('myElement',function(){
return {
restrict:"A",
scope : {},
link : function(scope, element, attrs, ngModel) {
(attrs.max_length>0?angular.element(element).attr("maxlength-
counter",""):'');
$compile(element.html())(scope);
}
});
이 몇 가지 코드를 표시 작업, 당신은 무엇을 시도를 사용하여 무엇 이건 당신은해야합니까? –
실제로 내가 지시어를 작성하고 요소에 속성을 조건부로 추가 한 다음 지시문을 호출하지 않았습니다. 그러나 속성을 정적으로 추가하면 지시문은 –
으로 다시 호출됩니다. 코드를 게시하십시오. –