Directive on ui-view is destroyed & re-linked on state-change
In short: When you have a directive on a named ui-view element, then the directive will be destroyed and re-linked when navigating to or from a state that absolute-references that named ui-view.
Setup:
- A html-file with two (sibling-) ui-views; one default, one named
- A custom directive on the named ui-view element
- Add 2 simple states that only use the default ui-view
- Add 1 state that uses the default ui-view and absolute-references the named ui-view
Steps to reproduction:
- Navigate to one of the ‘simple’ states
- Navigate to the state that references the named ui-view
- Navigate back to one of the ‘simple’ states
Expected behavior: › The custom directive on the named ui-view element should be linked at the start of the application, and in this scenario not be destroyed (ever)
Actual behavior:
› The custom directive is destroyed (eg its $destroy callback is called) and linked (link() is called) when navigating to or from a state that absolute-references the named ui-view. When navigating between the 2 simple states, this doesn't occur.
Plunkr: http://plnkr.co/edit/pFKLCnYPoRXbaAkPL4uM?p=preview (let me know if you'd rather read normal, non-coffee javascript)
Another side-effect of this problem is that jQuery.cleanData is run after linking the second scope, but before any watches set up by the link have fired. This causes interesting errors if using things like jSignature if you try and use them in the watch.
http://plnkr.co/edit/1pbKhsDZtGaC4MNyFOJy?p=preview
+1 This is odd behavior and can be nasty in some situations.
+1
+1 Also experiencing this..
This is pretty counterintuitive to the idea that a link function should only run once. For anyone who is doing any sort of "one time setup" for a directive in their linking function they now have to implement some way of detecting if it's already been ran or not.
+1
+1
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions.