Changes in the view are delayed due to updating metatags on the DOM in Angular 8

My component is in need of updating the view following an HTTP call. The scenario involves displaying a record after retrieving data from the server.

In the HTML file, we have-

 <mat-spinner *ngIf="loading"></mat-spinner>
<span *ngIf="!loading">This is my record </span> {{record}}

The TypeScript code goes like this-

constructor(private ngZone: NgZone) {}

ngOnInit(){
    this.loading = true;
    this.callServer():
}

callServer() {
    this.service.callServer()
        .subscribe(
            (data) => {
                this.onSuccess(data);

            },
            (error) => this.onError(error)
        );
}

onSuccess(data) {
    this.loading = false;
    this.record = data;
    this.addGoogleMetaTags(this.record);
}

addGoogleMetaTags function is responsible for manipulating meta tags within the document using Angular's Meta service. Due to its time-consuming nature, there is a delay in updating the view after fetching the data. Even after attempting to trigger change detection or calling the Google function outside of Angular, the issue persists.

this.zone.runOutsideAngular(() => this.addGoogleMetaTags(this.record));

Is there a way to instantly reflect the changes in my application without waiting for the completion of addGoogleMetaTags?

Answer №1

A simple solution to the issue was implemented by adding a timeout of 0 to the following line of code:

this.updateSocialMediaTags(this.data)

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

What strategies can I employ to prevent the Unexpected token error from occurring while working with django and javascript?

Attempting to transfer data from my Django application to JavaScript based on the solutions provided in this question views.py context['username'] = json.dumps(request.user.username) test_script.js document.write('Script working') use ...

Steps to combine NativeScript and Angular CLI

Exploring the potential of integrating NativeScript with Angular CLI to develop applications for both web and native mobile platforms. I attempted to use Nathan Walker's NativeScript Magic, but encountered difficulties creating a fresh application wit ...

What is the reason behind TypeScript selecting a different overload when referencing a function versus when calling it within a lambda wrapper?

What is the reason for TypeScript selecting the last overloaded variant instead of the middle one in the last case, resulting in a type of (string | null)[] instead of string[]? (Version 4.4.4 of TypeScript) function f(x: null): null; function f(x: string ...

Tips for successfully passing an object via a Link

I am trying to pass an object through a Link component in react-router v6. Can someone please guide me on how to achieve this? Below is a snippet of my code where the user should be directed to another component. import React from 'react' import ...

Utilizing Apps Script for tallying background colors in Google Sheets

Sorry for the lengthy explanation! Let me know if you need more details or examples from the JavaScript file/spreadsheet I'm working with. Situation: I'm facing challenges with Google Apps Script (GAS) while trying to count the number of backgro ...

Utilizing v-model dynamically to showcase the outcomes of a specific property within a v-for iteration

As I iterate over an array using v-for, the number of items in this array varies each time. Currently, I am able to input values into the fields and have them correctly update the data property associated with them. However, there are two issues that need ...

What is the best way to adjust the size of a kendo ui combobox?

Is there a way to adjust the width of the kendo ui combobox? My current version is 2012.3.1114 I've attempted to modify it using the following CSS: #options { padding: 30px; } #options h3 { font-size: 1em; font-weight: bold; margin: 2 ...

Requiring a landing page to be shown to each individual visitor

I am in the process of creating a landing page for an upcoming music release. I want to display this splash page every time a visitor lands on the home page, without setting the splash page as the base href. Would using JavaScript be the most effective m ...

Struggling with the integration of a custom login feature using next-auth, leading to being constantly redirected to api/auth/error

Currently, I am facing a challenge while working on my Next.js application. The issue lies with the authentication process which is managed by a separate Node.js API deployed on Heroku. My objective is to utilize NextAuth.js for user session management in ...

The custom resolver for product page metadata is not being activated

I'm having an issue with implementing Meta Description on my PDP page in Spartacus version 6.5. I have added a resolver that extends ProductPageMetaResolver into the providers section of my custom product.module file. However, for some reason, my &apo ...

What method can be used to integrate Typescript into Cypress testing?

Struggling to transition my Cypress test framework from JavaScript to TypeScript has been quite challenging for me. Despite following numerous online tutorials, I'm unable to make it work smoothly. While working on my Login.ts file, I encountered an ...

AngularJS modals enable users to interact with the background content in a

I'm looking for a way to enable users to drag and drop elements from the modal onto the background. Although my current modal is functioning well, it does not allow me to interact with elements on the background: var asideInstance = $aside.open({ ...

Leveraging the power of TypeScript and Firebase with async/await for executing multiple

Currently, I am reading through user records in a file line by line. Each line represents a user record that I create if it doesn't already exist. It's possible for the same user record to be spread across multiple lines, so when I detect that it ...

Techniques for manipulating multiple circles with JavaScript

After creating a series of circles with d3, I successfully implemented the functionality to drag individual circles and track their positions. var width= 800; var height=600; svg= d3.select("body").select(".div1").append("svg") ...

Encountering an unforeseen change in the "buttonText" attribute

I've developed a simple Vue.js component for a button. When the button is clicked, it should display the text "I have been clicked." It does work as expected, but I'm also encountering an error that reads: 49:7 error Unexpected mutation of "but ...

What process does JavaScript use to interpret indexing?

function highlightRow(searchRow) { if(searchRow != null) { var oRows = document.getElementById('Table').getElementsByTagName('tr'); //use row number to highlight the correct HTML row ...

Obtain distinct values from an array of dictionaries and form a new dictionary

Looking at the JSON data provided below: [{ "name": "Il Brigante", "rating": "5.0", "match": "87", "cuisine": "Italian", "imageUrl": "/image-0.png" }, { "name": "Giardino Doro Ristorante", "rating": "5.0", "match": "87", ...

Issue with running Chrome and tests correctly in CI/CD job, despite successful local execution with Angular, Karma, and Gitlab

I'm currently encountering an issue with my Karma test job for a CI/CD pipeline on GitLab connected to a Kubernetes cluster where my GitLab runner is configured. Here's the problem: When I execute "ng test" with ChromeHeadless on my local machin ...

Enhance the appearance of an angular custom component with unique styling

I have developed a unique custom angular element called my-component and in its stylesheet I've added the following: :host { display: inline-block; width: 55px; } Now, when using my-component in another component's template, I tried to ...

Fade in only a single element from a specific class using Jquery

I recently attempted to create a script that would fade in a tooltip when hovering over a link or image. Everything was working fine except for the fact that only one tooltip would appear at a time. In other words, I wanted to hover over an image and have ...