Preventing AdSense ads from showing on an Angular localhost using Ng-if

I've been trying to prevent adsense ads from loading in angular using the following code:

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

While the script works fine and logs okay in the console during testing, it doesn't seem to work when live. I'm guessing this could be because of the delay between the check being executed and the host resolving. Would it be better to use something like this instead?

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

Any insights would be greatly appreciated!

Answer №1

To set up your controller, you might consider implementing something similar to this:

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

Then in your HTML file:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery is in a constant state of indecision when it comes to determining the best way to manage buttons

A straightforward scenario. When a checkbox is checked, it activates a disabled button. Unchecking the box disables the button again. Sample Code: jQuery -> $('#subscribe_button').attr('disabled','disabled') $("[name= ...

What steps can I take to modify my webpage, like a dashboard, on the internet?

Whenever I click on a menu item in the sidebar of my HTML file, I want only the body section to change without affecting the navigation or sidebar content. For instance, if I select the "Coding Convention" menu in the sidebar, I would like the page to swi ...

Pull the data from jQuery/JavaScript/AJAX and store it in the database using ASP.NET/C#

I am working on creating a form that includes textboxes and a five star rating feature. The goal is to save the data entered in the fields into a database upon submitting. While implementing the textboxes was straightforward, I am facing challenges with e ...

Add an input element to a form fieldset by employing vue

In my form, I have a staged approach with 3 fieldsets that only appear when the "Next" button is clicked. Now, in the third fieldset, I need to add input elements based on keys extracted from an external json object. Data: data: () => ({ c ...

"Sorry, MongoDB seems to be having trouble with the pretty() function at the

Every time I attempt to extract information from a Mongodb database, an error keeps popping up: The problematic part of the code is located right here: ...

Building an AngularJS Service with TypeScript that is Non-Singleton: A Step-by-Step Guide

I need help converting an AngularJS Typescript Service into a Non-Singleton. Can anyone provide guidance on how to achieve this? (Note: This is not the same as other questions that focus on achieving this in JS) I have included some simple pseudo code be ...

Extract information from an external HTML table and store it in an array

I am looking for a way to extract data from an HTML table on an external site and save it as a JSON file for further manipulation. Is there a method to retrieve table data from an external HTML site that differs from the code example provided? Additional ...

Utilizing Nicknames in a JavaScript Function

I'm dealing with a function that is responsible for constructing URLs using relative paths like ../../assets/images/content/recipe/. My goal is to replace the ../../assets/images section with a Vite alias, but I'm facing some challenges. Let me ...

Challenges with accurately displaying models in three.js

I am facing some difficulties while using three.js to render a model completely white with wireframe. Instead of rendering the model as desired, it appears solid black. I have tried assigning a white material to the model but it had no effect. Additionally ...

Can you explain how I can configure the express module for routing?

directories /config -routes.js /public /views -index.pug /home -home.pug -app.js app.js const express = require('express'), app = express(); app.use(express.static(path.join(__dirname, 'public'))); app.se ...

Firebase Functions utilizing Realtime Database to update nested child data

Every 10 minutes, a child is created inside my Realtime Database in Firebase through a webservice that sends data via the Rest API. When this data arrives, a function picks it up. The node contains various values, but the important one for further processi ...

steps for integrating react-pannellum library into react/ionic

Trying to integrate a 3D panorama view into my React Ionic app, but encountering an error while attempting to install using either of the following commands: npm install --save react-pannellum npm install --save pannellum > npm WARN config global `-- ...

What is the best way to display label information on a Google line chart?

line graph column graph My graph continuously calls the Controller to fetch recent data from the Database. There are two lines on the graph, and I would like to display the names of each line (column) such as red=counts of something // brown=counts of so ...

The dropdown consistently shows a value of zero

I am toggling the visibility of a div based on the selection from a Dropdown menu, but for some reason, the dropdown is consistently returning a value of 0. $(document).ready(function() { $('#rel_status').on('change', function() { ...

What is the procedure for altering the location of a mesh within the animate() function in three.js?

In my implementation of a three.js mesh (found in three.js-master\examples\webgl_loader_collada_keyframe.html), I have a basic setup: function init() { ... ... var sphereGeometry = new THREE.SphereGeometry( 50, 32, 16 ); var sphereMater ...

A Step-by-Step Guide to Transferring Information from SAML Response to Angular App in Web API and Loading the

After successfully adding SAML support to the backend of our WebAPI following OKTA authentication, a new challenge has emerged. We now face the dilemma of establishing a connection with our AngularJS app when the browser itself serves as the triggering po ...

Refresh numerous HTML <div>'s using data from a JSON object

Looking to automatically update the homepage of my website with the ten most recent "posts" from the server. Here's an example HTML format: <div id="post1"> <p id="link"> </p> </div> <div id="post2"> <p id="li ...

Run scripts once all promises have been successfully fulfilled using Jquery

I've been having trouble figuring out how to properly utilize the when function in my code. My ultimate goal is to trigger a window.location.reload when all AJAX requests have been completed. If I place the window.location.reload after the "each" loo ...

Make radio button disappear when clicked using JavaScript

My goal is to conceal radio button values upon clicking them, and while I have achieved this in a static context, I am seeking a dynamic solution. Here is an example of my current static implementation: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Tran ...

Is it possible to conditionally call the Apollo Client in my Vue template script?

I have a scenario where I pass a query to the apollo client in my template file using a script tag. However, I want to find a more efficient way to handle this without having to specify the query every time. My idea is to pass a boolean value through a pro ...