a" /> a" /> a"/>

Ng-if to not display adsense ads on angular localhost

328 Views Asked by At

I'm using the following to attempt to stop adsense ads from loading in angular"

<div class="" ng-if="window.location.host.indexOf('localhost') < 0">
ads here
</div>

The script logs okay in the console but doesn't work when live. Is this due to the difference between the time the check ran and the resolved host? Or should I be using something like:

<div class="" ng-if="$location.host().indexOf('localhost') < 0">
ads here
</div>

Thanks

1

There are 1 best solutions below

2
PrinceG On BEST ANSWER

In your controller, you can define something like:

$scope.enableAds = $window.location.host.indexOf('localhost') < 0;

and in your HTML

<div class="" ng-if="enableAds">ads here</div>