Angular 4's Mddialog experiencing intermittent display problem

While using MDDialog in my Angular app, I've encountered a couple of issues. Whenever a user clicks on the div, flickering occurs. Additionally, if the user then clicks on one of the buttons, the afterclose event is not triggered.

Can anyone provide suggestions on how to address these problems?

Here is the code snippet for calling the dialog:


private openDialog(data) {

    const dialogRef = this.dialog.open(DialogComponent, { width: 
            '350px', height: '100px', disableClose: true});
    dialogRef.updatePosition({ top: '95px' });

    dialogRef.afterClosed().subscribe(result => {

        this.dialogResult = result;

        console.log('dialogResult : ' + this.dialogResult);

        if (this.dialogResult) {
            this.Home();
        }

    });
    this.dialogResult = '';
 }

Dialog HTML:


<div md-autofocus>
   <div md-dialog-container>
   <h2 md-dialog-title>Information</h2>
   <md-dialog-content> Do you want to proceed? </md-dialog-content>
   <div md-dialog-actions>
      <div class="dialogButtons">
         <button  id= "YesButton" class="dialogButton"
            (click)="dialogRef.close(true)">Yes</button>
         <span class="flex1margin"></span>
         <button   id="NoButton" class="dialogButton"  
            (click)="dialogRef.close(false)">No</button>
         </div>
       </div>
     </div>
 </div> 

Dialog Component TypeScript:


import { Component, OnInit } from '@angular/core';
import { MdDialogRef } from "@angular/material";

@Component({
selector: 'your-dialog-selector',
templateUrl: './dialog.component.html'
})
export class DialogComponent {
     constructor(public dialogRef: MdDialogRef<any>) {
  }
}

Answer №1

A mistake was made when attempting to call the .close() method on the dialog object. Instead of using dailogRef, it should be dialogRef

 <button  id= "YesButton" class="dialogButton"
    (click)="dailogRef.close(true)">Yes</button>
 <span class="flex1margin"></span>
 <button   id="NoButton" class="dialogButton"  
    (click)="dailogRef.close(false)">No</button>
 </div>

This code should actually look like this:

 <button  id= "YesButton" class="dialogButton"
    (click)="dialogRef.close(true)">Yes</button>
 <span class="flex1margin"></span>
 <button   id="NoButton" class="dialogButton"  
    (click)="dialogRef.close(false)">No</button>
 </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

Choosing a dynamic dropdown option using jQuery and AJAX

I am facing an issue with a select box that is dynamically populated and should display information about a single option. The problem I am encountering is that the browser does not trigger a ':selected' event when I click on any of the options. ...

Preventing an infinite re-render loop caused by event listeners in React

One functional component is causing me some trouble: export default function Nav({photo}) { const [isOpen, setIsOpen] = useState(false) const [width, setWidth] = useState(window.innerWidth); const breakpoint = 768; useEffect(() => { ...

Building Your Own Array Object in JavaScript

Yes, it may seem crazy at first glance, but let me clarify things a bit. When using Jquery, for instance $('div'), it returns an Array Collection similar to this: [div#container, div#header, div#logo]. The interesting part is that primitive Arra ...

Show a persistent header once you scroll past a certain point using Bootstrap

Utilizing Bootstrap affix property to reveal a header after scrolling down by 100px has been successful for me. However, I encountered an issue when trying to set the opacity property to 0.0001, it works as expected. But when setting it to 0 or changing di ...

Finding the source of the err.kind expression in the MERN stack: Unraveling the mystery

Recently, I've been delving into the world of MERN stack development and came across an interesting technique for Error Handling in a tutorial. The tutorial showcased various expressions that can be used to identify different types of errors being thr ...

Leaflet setStyle changes are effective when applied through the console but do not reflect in the actual

I currently have a map with around 1000 polygons that I am loading onto it. My goal is to color these polygons based on a specific property value. The code snippet below showcases my approach, but the results are not as expected. mapLayerFieldGrid = new L ...

Encountering a Vue syntax error following the binding of a session variable

Encountering a syntax error while attempting to bind a session variable as a prop of my Vue component. Scrutinizing my code did not reveal any mistakes, but perhaps another set of eyes may catch something. This is where I have registered my components: V ...

Incorporating video responses into an HTML player using Node.js with the req.pipe(res) method

I have successfully implemented ytdl-core to play a video and it is working as expected. Below is the code snippet: app.get('/',function(req,res) { var fs = require('fs'); var ytdl = require('ytdl-core'); ...

Sort through the array using a separate array in Vuejs

I am currently working with two arrays: { "products": [ { "name": "Jivi", "Hint": "45-60 IE/kg alle 5 Tage\n60 IE 1x/Woche\n30-40 IE 2 x/Woche", "frequency": ["1", "2", "8"] }, { "name": "Adynovi", ...

The navigate function fails to function properly in response to HttpClient

Hey there! I am facing an issue with the router.navigate function in Angular. When I try to use it within a subscribe method for httpClient, it doesn't seem to work as expected. Can someone please help me understand why this is happening and how I can ...

Angular directive for dynamic template inclusion

I am facing an issue while creating a directive that should automatically add tabs and their content. The problem I'm encountering is retrieving the content stored in partials/tabs/tab[x].html. In my code, I have defined a constant named AvailableTab ...

The ES Module's require() function is not supported. Please update to dynamic import() instead, which is compatible with all CommonJS modules

I'm encountering some difficulties with launching my Angular application. After running ng serve, I am seeing the following error message: An unhandled exception occurred: require() of ES Module C:\Users\******\Documents\GitHub&bso ...

Executing several Ajax requests at once can decrease the speed of the process

When I make simultaneous API calls using Ajax, the process seems to be slow as JavaScript waits for all API responses instead of fetching them asynchronously. For instance, /api/test1 usually responds in 5 seconds and /api/test2 also responds in 5 seconds ...

Click Event for Basic CSS Dropdown Menu

My goal is to develop a straightforward feature where a dropdown menu appears below a specific text field once it is clicked. $(".val").children("div").on("click", function() { alert("CLICK"); }); .container { display: inline-block; } .val { d ...

Is TypeScript's Structural Typing the exception to the rule?

Let me illustrate two scenarios where I encountered difficulties. The first example involves two points: one in 2d and one in 3d: type Point2D = { x: number, y: number }; type Point3D = { x: number, y: number, z: number }; let point2D: Point2D = { x: 10, ...

Using C# Selenium WebDriver to interact with JavaScriptExecutor for handling prompt windows

I am faced with a JavaScript Prompt Window that I need to handle. Previously, I was able to manage a simple prompt with only an 'OK' and 'Cancel' button using the following code: ((IJavaScriptExecutor)ts.getDriver()).ExecuteScript("win ...

Error in ng2-pdf-viewer: Invalid parameter object received. Please provide either the .data, .range, or .url parameter

Trying to integrate ng2-pdf-viewer into my Angular 7 project has been a challenge. Initially, I tackled a cors issue by following this advice. However, I am now faced with the error below: Invalid parameter object: need either .data, .range or .url at Obj ...

Is there a way to activate a function in a sibling component without using Prop Drilling?

Looking at the image, you can see the structure of components I have. <Invoice> <Left></Left> <Right></Right> </Invoice> In the Left component, there is a form, and in the Right component, there is a Submit button l ...

Dividing the text by its position value and adding it to a fresh object

I needed to divide the paragraph into sections based on its entityRanges. Here is what the original paragraph looks like: { type: 'paragraph', depth: 1, text: 'Do you have questions or comments and do you wish to contact ABC? P ...

Issue with react-native-svg ForeignObject missing in project (React Native with Expo using TypeScript)

I am working on a React Native project in Expo and have incorporated the expo TypeScript configuration. Using "expo install," I added react-native-svg version 9.13.3 to my project. However, every time I attempt to render the SVG using react-native-svg, I ...