Cannot override model.$render method in directive's link function (plnkr included)
My directive for jquery mobiscroll run very well on AngularJS 1.1.5. After upgrading to 1.2 rc3, it does not work any more. I put a break point inside $render method but angular not run into these statements. I did a downgrade to 1.2 rc2 and it works fine.
Here are 2 version of my example:
angular 1.2 rc2 (work as expected) http://plnkr.co/edit/gmef5FKzVRNz0syonddf?p=preview angular 1.2 rc3 version http://plnkr.co/edit/8GvWoU1yKI14Joi3VMhn?p=preview
update issue with plunker example
A simple fix is to add a positive priority in tinymce directive. In case you want to know more http://iwang.github.io/html/angular/angularjs/2013/11/04/ngmodel-render-cannot-be-overriden-in-angular-rc3.html
Try to add a positive priority in my directive & it works, $render works as normal! Read your article too. I wonder if the angular 1.2 stable release will keep this behavior or not (PostLinkPriority, low -> high). if so, we need to add priority to our custome directive one by one, don't we ? Thanks.
Saved me a day. thanks
Here is the cause of this: https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L462
It is overriding custom $render you might have set.
The bug is sensitive to directive name, for example if your directive is called inputMagic it will get overridden, however if the name is fooDirective it will work as documented in manual.
Workaround 1
Set priority : 1 or higher on your custom directive.
Workaround 2
Use $viewchangelisteners instead of $render, for example:
ngModelController.$viewChangelisteners.push(function(){
console.log('The new value is', ngModelController.$modelValue);
});
You could also decorate the input directive, I believe, and wrap the original link function with another
I think we can close this, as there are numerous workarounds for this. Another one I can think of in this special case is a formatter, that displays the date in the correct format.