Angular template ref modal not reflecting updated data after opening

In my login screen component, I have implemented 2 template refs within a modal. One for displaying a loading bar and the other for showing any errors that may occur.

While the loading bar successfully displays the "Logging in.." text during the login process, the error message is not being shown when an error occurs. Although the error message is logged in the console before opening the template, the modal opens to a blank screen.

Below is the HTML code snippet:

<ng-template #loadingTemplate let-data>
    <div class="loadingBar">
        <p class="loading-note">{{data.message}}</p>
        <mat-spinner></mat-spinner>
    </div>
</ng-template>
<ng-template #modalRoleSelect let-data>
    <div class="loadingBar">
        <p class="loading-note2">{{data.loginText}}</p>
    </div>
    <div style="display: flex;justify-content: flex-start;">
        <button style="margin: 10px 20px;font-weight: bold;letter-spacing: 0.5px;" mat-raised-button (click)="closeDialog()">Close</button>
    </div>
</ng-template>

Here is the TypeScript code snippet:

openTemplate(error: string) {
      console.log(error)
      const dialogRef1 = this.dialog.open(this.customTemplate, {
          data: {loginText:error},
         width: '470px'
      });
      dialogRef1.afterClosed().subscribe(() => {
        console.log('The dialog was closed');
      });
  }

Although clicking on radio buttons while the modal is open does display the error message, there seems to be an issue with change detection. Any help on resolving this matter would be appreciated.

Answer №1

I successfully resolved the problem on my own by invoking a template dialog within ngzone. As a result, it now verifies change detection and properly displays the Error.

this.zone.run(() => this.dialog.open(this.customTemplate, {
        data: {loginText:error},
       width: '470px'
    }))

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

Modify input field background color

In my Angular project, I have an input field structured like this: <input class="form-control" type="text" ng-model="newBook.color"> Whenever the value in this input changes, I want to dynamically change the background color of a specific div. Wit ...

Converting JSON into an HTML nested list structure

JSON: { "Item A": [ 5, { "Item A1" : 15, "Item A2" : 25, "Item A3" : 35 } ], "Item B": 45, "Item C": [ 55, { "Item C1" : 65, "Item C2" : 75, "Item C3" : 85 } ] } Desired HTML: <ul ...

Failing to send contact information using JSON in PHP

I attempted to transmit JSON data to PHP for email processing, but encountered an issue where the process veered into the 'else' condition during debugging. Here is the code snippet: HTML <form id="cbp-mc-form" class="cbp-mc-form" method="po ...

Testing HTTP calls in Angular 2 using Jasmine's spyOn

I want to monitor the Http service to ensure it is calling the correct endpoint. Is there a way to accomplish this? Currently, I am only testing that my services return data...I would like to expand their functionality. If you ever require it, here is my ...

Updating information within a form while keeping it editable, utilizing React with Redux but without redux-form

Issue https://i.sstatic.net/O1qDu.png I am encountering a problem with updating user information in my list. Here are the specific requirements: Choose a user to edit by clicking on their name. Edit the selected user's information and submit to up ...

Using only the $http.get method, you can easily retrieve data in a simple

Here is my message from JSP, I am attempting to extract information from the response. $http.get('url.jsp', data).then(successCallback, errorCallback); I encountered an issue with "data is not defined" https://i.sstatic.net/NX60Y.png Is there ...

Using AngularJS to automatically set the selected option from the model

Current Angular version - 1.2.28 (Legacy, pending upgrade) I'm currently facing an issue with setting the default selected value for a select element based on the model value. In my Controller, I have this code snippet; $scope.customer.country = &a ...

Having trouble populating the input text field with the selected value from a dropdown using JavaScript

I have implemented a JavaScript function to retrieve the id of a dropdown select with id='odrid'. The script looks like this: $('#odrid').change(function(){ $.getJSON( 'fetch.php', 'odrid='+$(&ap ...

Arranging an array according to the length of another parameter array

Consider this array as an example - [ { "data": [ 1, 2, 3 ] }, { "data": [ 2, 3, 4, 5 ] } ] I want to arrange the main array based on the length of data. The object with the largest data array should come first, and t ...

What is the best way to create a deep clone of an XMLDocument Object using Javascript?

I am currently working on a project that involves parsing an XML file into an XMLDocument object using the browser's implementation of an XML parser, like this: new DOMParser().parseFromString(text,"text/xml"); However, I have encountered a situatio ...

Exploring How to Identify and Eliminate Duplicate Objects in 2 Arrays

I'm working with two arrays of objects in JavaScript and my goal is to compare, merge the contents, and sort by id. Specifically, I want the final sorted array to include all objects from the first array, as well as any objects from the second array t ...

ReactJS: implementing conditional rendering using 'if else' statements in components

I'm currently facing an issue with a seemingly simple goal. For the react show page, my aim is to have an unordered list of the student's instrument sections under the "Instrument Section(s)" heading, which is relatively straightforward. I am ab ...

Error: The object referred to as "procedure" is invalid and cannot be executed as a function

At the moment, I'm delving into creating a small game using NodeJS to explore ES6 features. I've built a "Player" object with the new syntax. The static functions are working perfectly fine. However, when it comes to calling its methods, I encoun ...

Passport.js does not provide authentication for server-side asynchronous requests

Recently, I configured Passport.js with the local-strategy on my express server. Interestingly, when I am logged in and send an asynchronous request within NextJS's getInitialProps, it allows the GET request through client-side rendering but not serv ...

Issues with Bootstrap carousel animations experiencing glitches

I recently implemented a carousel that showcases 3 items at a time and advances by one. After clicking the next button, I noticed that the 2nd and 3rd items disappear momentarily before reappearing. This animation glitch is not smooth, and I would like al ...

The Recharts Line chart fails to display newly added data points when data is updated

My app features a straightforward tool that enables users to monitor their weight changes over time. Despite successfully receiving new data in the props, the chart does not update and display the new point. Recharts Component: import React from 'rea ...

Sharing context sub files in Next.js can be easily accomplished by following a few simple

These are the pages on my website: /pages /gift /[slug] index.tsx /personalize index.tsx In /gift/[slug]/index.tsx, I have a component called GiftProvider that looks like this: return ( <GiftProvider gift={gift}& ...

Toggle the visibility of a material progress bar on the app component using child components

I'm currently learning Angular and have a small question about it. In my App component, I have a Material Progress bar like this: <mat-progress-bar mode="indeterminate" *ngIf="IsLoading"></mat-progress-bar> <router- ...

Utilizing the .finally method on a promise that is already being handled with try/catch statements elsewhere may lead to an UnhandledPromiseRejection

Recently, I've come across an unexpected behavior while working with nodejs. To illustrate this strange occurrence, let's consider the following example: Imagine we have two functions, foo and bar. The foo function creates a promise, attaches a ...

Searching for two dates that fall on the same day

My July dates array looks like this: const dates = [ { date: '2023-07-01', available: true }, { date: '2023-07-02', available: true }, { date: '2023-07-03', available: true }, { date: '2023-07-04', ...