以前有人遇到过这种行为吗?0directive('validFile', function (utils, $filter) {返回 {要求:'ngModel',链接:函数(范围、el、attrs、ngModel){如果(utils.isMobileAgent())返回;var form = el.parents().find('form');ngModel.$render = 函数 () {调试器;if(form.hasClass('ng-pristine'))返回;if(el.val() && el.val().length > 0){ngModel.$setViewValue(el.val());}if(el.hasClass('ng-invalid')){el.parent().addClass('ng-invalid').addClass('ng-invalid-required');ngModel.$setValidity(attrs.name, false);ngModel.$setPristine(attrs.name, false);scope.fileMsg = $filter('translate')('PLEASESELECT') + ' ' + $filter('translate')(attrs.name);//scope.layout.showFileError = true;}别的{el.parent().removeClass('ng-invalid').removeClass('ng-invalid-required').addClass('ng-valid');ngModel.$setValidity(attrs.name, true);}};el.bind('鼠标悬停', function(){if(form.hasClass('ng-dirty') && el.parent().hasClass('ng-invalid'))el.removeClass('ng-pristine');});el.bind('mouseleave', function(){if(el.val() && el.val().length > 0){el.addClass('ng-pristine');}})el.bind('改变', 函数 () {范围.$应用(函数(){ngModel.$render();});});form.bind('change', function () {范围.$应用(函数(){ngModel.$render();});});}};});标记:<input type="file" data-ng-model='model.formData.resume' name="resume" data-valid-file data-my-validate data-value-required="true> 解决方案 将指令的优先级提高到 0 以上.例如:myApp.directive('validFile', function ($filter) {返回 {优先级:10,这是一个我发现与这个ui-tinymce问题相关的问题的详细解释从根本上说,这与您的相同.简短版本的解释是此更改导致input的 $render 优先于您自己的.通过提高你的指令的优先级,你实际上给了你的 $render 优先级 - 就像在 1.2 rc3 中的改变之前一样.I have migrated from angular 1.0.8 to angular 1.2.2 yesterday, and beside a bunch of other things that got broken and I've already fixed, the $render function on the following directive is not firing anymore.Did anyone encouter such a behavior before?0directive('validFile', function (utils, $filter) { return { require: 'ngModel', link: function (scope, el, attrs, ngModel) { if(utils.isMobileAgent()) return; var form = el.parents().find('form'); ngModel.$render = function () { debugger; if(form.hasClass('ng-pristine')) return; if(el.val() && el.val().length > 0){ ngModel.$setViewValue(el.val()); } if(el.hasClass('ng-invalid')){ el.parent().addClass('ng-invalid').addClass('ng-invalid-required'); ngModel.$setValidity(attrs.name, false); ngModel.$setPristine(attrs.name, false); scope.fileMsg = $filter('translate')('PLEASESELECT') + ' ' + $filter('translate')(attrs.name); // scope.layout.showFileError = true; } else{ el.parent().removeClass('ng-invalid').removeClass('ng-invalid-required').addClass('ng-valid'); ngModel.$setValidity(attrs.name, true); } }; el.bind('mouseover', function(){ if(form.hasClass('ng-dirty') && el.parent().hasClass('ng-invalid')) el.removeClass('ng-pristine'); }); el.bind('mouseleave', function(){ if(el.val() && el.val().length > 0){ el.addClass('ng-pristine'); } }) el.bind('change', function () { scope.$apply(function () { ngModel.$render(); }); }); form.bind('change', function () { scope.$apply(function () { ngModel.$render(); }); }); }};});markup:<input type="file" data-ng-model='model.formData.resume' name="resume" data-valid-file data-my-validate data-value-required="true"> 解决方案 Increase the priority of your directive to something above 0.For example:myApp.directive('validFile', function ($filter) { return { priority: 10,Here's a detailed explanation of the problem that I found associated with this ui-tinymce issue that's, at it's root, the same as yours.The short version of the explanation being that this change causes input's $render to take precedence over your own. By bumping the priority of your directive you, in effect, give your $render priority- as it was before that change in 1.2 rc3. 这篇关于$render 在 angular 1.2.2 停止工作(文件验证指令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 18:11