Skip to content

Can't destroy on ngAfterViewInit #58

@pacocom

Description

@pacocom

Bug, feature request, or proposal:

I want a conditional destroy popover on ngAfterViewInit or better if it possible open popoverDiscount only with programmable code WITHOUT using mdePopoverTriggerFor.

<mat-toolbar color="primary">
  <h1>Angular Material Popover Example</h1>
  <div class="fill-space"></div>
  Popover is  <span class="popover-status">{{ popoverDiscountTrigger.popoverOpen ? 'opened' : 'closed' }}</span>
</mat-toolbar> 

<mde-popover
    #popoverDiscount="mdePopover"
    [mdePopoverOverlapTrigger]="false"
    [mdePopoverCloseOnClick]="false"
>
    Conditional popoverDiscount
    <button class="icon-popover-close" (click)="popoverDiscountDestroy()">Close</button>
</mde-popover>

<button
    #popoverDiscountTrigger
    [mdePopoverTriggerFor]="popoverDiscount"
    mdePopoverTriggerOn="click"
    [mdePopoverBackdropCloseOnClick]="false">
    POPOVER CLICK
</button>
import { Component, AfterViewInit, ViewChild } from '@angular/core';
import { MdePopoverTrigger } from '@material-extended/mde';


@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular 8';

  @ViewChild(MdePopoverTrigger, { static: true }) popoverDiscountTrigger: MdePopoverTrigger;

  ngAfterViewInit(): void {
    const condition = false;

    if (condition) {
      this.popoverDiscountTrigger.openPopover();
    } else {
      this.popoverDiscountTrigger.destroyPopover();
      // NO!, Not destroy popoverDiscountTrigger
    }
  }

  popoverDiscountDestroy(): void {
    this.popoverDiscountTrigger.destroyPopover();
    // YES!, destroy popoverDiscountTrigger
  }
}

What is the expected behaviour?

I want to destroy popoverDiscount on ngAfterViewInit or Toggle popoverDiscount without directive mdePopoverTriggerFor, that is, only with programmable code.

What is the current behaviour?

In the code above if condition is false don't destroy popoverDiscount, that is, if I click on button #popoverDiscountTrigger, the popover appears:

What are the steps to reproduce?

Provide a working example using StackBlitz (or similar) to reproduce the problem.
https://stackblitz.com/edit/mde-popover-rlehwh

What is the use-case or motivation for changing an existing behaviour?

Because I want total control to open, close or destroy popover using programmable code.

Which versions of Angular, Material-Extended, OS, TypeScript, browsers are affected?

Angular 8

"dependencies": {
  "@angular/animations": "^8.1.1",
  "@angular/cdk": "^8.0.2",
  "@angular/common": "^8.1.1",
  "@angular/compiler": "^8.1.1",
  "@angular/core": "^8.1.1",
  "@angular/forms": "^8.1.1",
  "@angular/material": "^8.0.2",
  "@angular/platform-browser": "^8.1.1",
  "@angular/platform-browser-dynamic": "^8.1.1",
  "@angular/router": "^8.1.1",
  "@material-extended/mde": "^2.3.1",
  "@mdi/font": "^3.8.95",
  "@nrwl/angular": "^8.2.0",
  "axios": "0.19.0",
  "bulma": "^0.7.5",
  "core-js": "^3.1.4",
  "express": "4.17.1",
  "form-data": "2.5.0",
  "hammerjs": "^2.0.8",
  "html5shiv": "^3.7.3",
  "material-design-icons": "^3.0.1",
  "normalize.css": "^8.0.1",
  "respond.js": "^1.4.2",
  "rxjs": "~6.5.2",
  "rxjs-compat": "^6.5.2",
  "web-animations-js": "^2.3.2",
  "zone.js": "^0.9.1"
},

Other Comments

Very Thank!

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions