angularjs - on page redirect, Angular directive's event listener misses jQuery event trigger -
tl;dr
i need angular linking function occur before jquery click event triggered on page redirect.
i have angular directive waits jquery click event in linking function:
// link: function(scope) { angular.element('#parent-selector').on('click', '#buttonid') { // force digest since looking outside of angular scope.$apply(function() { // stuff looks outside of angular }); } }
my goal make stuff happen. when click button, happen, , makes me happy. can click again , again , again, , stuff happens; can reload page , click button, , stuff still happens, , sufficiently satisfied.
well, have different button in different view different url 1 triggers click event lives. when button clicked, redirects view angular directive , jquery click event. upon redirect, calls jquery click event trigger functionality desire, no avail. sad.
// along these lines $('#buttonid').trigger('click');
using 'debugger' , looking in chrome dev tools have been able ascertain following:
when works, , happy, because angular directive's linking function loads first. makes sense, since directive can set listener before event triggers.
when doesn't work, , sad, because angular directive's linking function loads after jquery click event triggers. note still listening event, subsequent clicks of button trigger stuff, expected.
but first trigger, forced click on page redirect, occurring before linking function has opportunity listen it.
any thoughts, suggestions, questions? know bit vague, , apologize that. happy provide more details. key note working, exception of timing of events. expect stuff happen desire if only, after redirect, angular linking function can load before click trigger.
i able solve issue using angular page redirect, accomplished passing $window directive dependency.
// on redirect... if ($window.location.hash == '#some-hash') { // stuff want done }
note doesn't solve issue. consider hack functionality want work.
but question still remains: why angular directive's link function happen after jquery trigger on page redirect, rather before on page reload (even when make jquery wait document ready or window load)?