Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Cannot override model.$render method in directive's link function (plnkr included) #4560

Closed
EthanNguyenDev opened this issue Oct 21, 2013 · 7 comments

Comments

@EthanNguyenDev
Copy link

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

@EthanNguyenDev
Copy link
Author

update issue with plunker example

@iwang
Copy link

iwang commented Nov 4, 2013

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

@EthanNguyenDev
Copy link
Author

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.

@dlin-me
Copy link

dlin-me commented Nov 7, 2013

Saved me a day. thanks

@Thinkscape
Copy link

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);
});

@caitp
Copy link
Contributor

caitp commented Dec 12, 2013

You could also decorate the input directive, I believe, and wrap the original link function with another

@Narretz
Copy link
Contributor

Narretz commented Jul 21, 2014

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants