Schwertfisch Schwertfisch - 1 year ago 104
AngularJS Question

Angularjs - does ng-switch have a content loaded event?

I have a ng-switch with different contents, one of them is a Gallery and I have to set the JQuery event to all images after switch ng-switch-when=gallery content is ready, but not lucky because it's firing the event before the content is loaded.

the gallery is the third ng-switch-when so I can't set the events with a ng-init.

So, does ng-switch have a content loaded event or directive?

<a href="" ng-click="menuSelection='gallery';loadLibraryGallery();">GALER&Iacute;A</a>


$scope.loadLibraryGallery = function(){
//I have to set this event to childrens after ng-switch-when=gallery is loaded


Any idea. Please
Thank you.

Answer Source

You can view the ngSwitch directive's source on github It never calls any $broadcast nor $emit functions so no, it doesn't have such event.

You could try creating your own directive, which is really simple. This directive is going to be linked after the html code has been inserted.

Let's say this is your code:


<ANY ng-switch="expression">
    <ANY ng-switch-when="matchValue1" data-gallery>...</ANY>
    <ANY ng-switch-when="matchValue2">...</ANY>
    <ANY ng-switch-default>...</ANY>


angular.module('app').directive('gallery', function(){
     return function ($scope, $element, attrs) {

Remember, that you should never modify DOM or call code that modifies DOM from the controller. This is directives job.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download