2013-04-18 2 views

답변

2

setviewvalue 대신 자연 모델 설정 기 scope[attrs.ngModel]을 사용하십시오.

app.directive('format', function($filter) { 
    return { 
    require: 'ngModel', 
    link: function(scope, element, attrs, ctrl) { 
    element.unbind('input').unbind('keydown').unbind('change'); 
     element.bind('blur', function() { 
      if (element.val()) { 
       scope.$apply(function() { 
        scope[attrs.ngModel] = element.val(); 
       });   
      } 
     }); 

     ctrl.$formatters.unshift(function(modelValue) { 
      if (modelValue) { 
       var formatted = $filter('currency')(modelValue); 
       return formatted; 
      } 
     }); 
    } 
} 
}); 

올바르게 작동하려면 파서가 필요합니다.

+2

대단하네요. ng-model이 ng-model = "entry.test"와 같은 것일 수도 있습니다. ng-repeat 안쪽에 있습니다. – foxx

+0

그냥 attrs.ngModel.split (".")을 수행 한 다음 범위 속성을 반복합니다 – roemer

+1

꽤 해킹했습니다 – cdmckay