ianmurrays / ngDfp

DoubleClick For Publishers for Angular JS
MIT License
52 stars 39 forks source link

Can I pass a custom callback function of my own? #41

Open mihaisavezi opened 8 years ago

mihaisavezi commented 8 years ago

I'm reading through the sourcecode and looking for a way to pass a callback function to check after the slot has rendered if it is empty, with the isEmpty method available on DFP.

I found where I can call that method in the source, but I'm looking for a way to pass a callback function when I define a slot.

Not an issue with the library, it does what it says. I'm trying to take a stab at this myself, but I can't see how it can be done.

Did anyone try this?

e.g. in my case, because currently the directives data-ng-dfp-ad-hide-when-empty data-ng-dfp-ad-container are not working for me and I need to hide my container.

I apologise if this is not the place for such questions, as it's not a technical issue more of a " does this feature exist " kind of thing.

mihaisavezi commented 8 years ago

I just realised that you can use other elements of the DFP API on your own, without using ng-dfp.

In my case, I could add an event listener for the slot in the controller associated with that slot. Like this:

googletag.cmd.push(function() {
            googletag.pubads().addEventListener('slotRenderEnded', function(event) {
                if(event.isEmpty) {
                    $scope.isEmpty = true;
                }
            });
        })

Sure it's not the most elegant thing, but it works.