View loading and javascript that changes elements in the view
30 views
Skip to first unread message
alis...@codebrane.com
unread,
Jul 27, 2015, 10:23:06 AM7/27/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AngularJS
Hiya,
I must be missing something but there doesn't appear to be a way to get javascript to work with a view. e.g. a view contains elements that are changed by another javascript framework (photoswipe) but when the javascript runs in index.html the view doesn't exist so it fails. If I add onload to ng-view to get the controller to run the photoswipe init function it causes rootScope:infdig. document onready runs before the document is 'ready' i.e. before the template has loaded. Is there a best practice for using other frameworks with angular that require javascript to be run after the template is loaded?
thanks,
Alistair
Sander Elias
unread,
Jul 27, 2015, 10:44:24 AM7/27/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AngularJS, alis...@codebrane.com
Hi Alistair,
Have a look at the $viewContentLoaded event of ngView.
In your controller you can do something like:
$scope.on('$viewContentLoaded',function(){ //kick of your 3rth party thing. })
Does that help you a bit?
Regards
Sander
alis...@codebrane.com
unread,
Jul 27, 2015, 11:02:29 AM7/27/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AngularJS, sande...@gmail.com
thanks Sander but that's what I do. I took the document onready code out to a separate function and call it from viewContentLoaded. That's when I get the infdig error. The javascript in PhotoSwipe seems to cause the angular view to reload, which calls viewContentLoaded, which tells PhotoSwipe to init which causes angular to reload...
Alistair
alis...@codebrane.com
unread,
Jul 27, 2015, 11:28:29 AM7/27/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AngularJS, sande...@gmail.com, alis...@codebrane.com
After removing the otherwise route I got to see PhotoSwipe adding query params to the url based on gallery stuff. That seemed to be causing a route reload and redirect, which added query params, which reloaded, which redirected and so on. Turns out it's PhotoSwipe and there's a simple solution. history: false