What is the best way to pass the modal dialog parameter sent from HTML to the TypeScript page?

I have implemented a dialog window using Angular where it opens by passing a parameter in the HTML side along with a transaction. To further enhance the functionality of my page, I want to incorporate the fab button. However, I am facing a challenge in sending the parameters from the HTML side when calling the modal function on the TypeScript side. Can anyone assist me with this?

.html file((click)="editPdf(responsiveData)")

.... <!-- The part to be deleted -->
<button type="button" class="btn btn-outline-primary btn btn-sm dropdown-toggle mr-3" (click)="editPdf(responsiveData)"> <i class="fe-edit"></i></button>
...
<div>
<div id="fab-dismiss"
     *ngIf="fabTogglerState==='active'"
     (click)="onToggleFab()">
</div>

<div class="fab-container">
  <button mat-fab class="fab-toggler"
          (click)="onToggleFab()">
    <i class="material-icons" [@fabToggler]="{value: fabTogglerState}">settings</i>
  </button>
  <div *ngFor="let btn of buttons" [@speedDialStagger]="buttons.length">
    <button *ngIf="btn.show"
            mat-mini-fab
            class="fab-primary"
            matTooltip="{{btn.tooltip}}"
            matTooltipPosition="left"
            color="accent"
            (click)="onClickFab(btn)">
      <i class="material-icons">{{btn.icon}}</i>
    </button>
  </div>
</div>

ResponsiveData content enter image description here

Typescript

...
FabOptions = {
    buttons: []
}
buttons = [];
fabTogglerState = 'inactive';
  fabButtons(ap: extendedAppeal) {
this.FabOptions = {
  buttons: [
    {
      ...
    {
      id: 9,
      icon: 'create',
      show: ((this.pdfguncelle) && (ap.status === this.appealStatus.Waiting) &&(this.authService.currentUser().agentOf.indexOf(ap.branchOfficeId) > -1)) ? true : false,
      tooltip: "Dilekçe Düzenle"
    },
    ...
  ]
};
}

showItems() {
   this.fabTogglerState = 'active';
   this.buttons = this.FabOptions.buttons;
}
hideItems() {
   this.fabTogglerState = 'inactive';
   this.buttons = [];
}

onToggleFab() {
   this.buttons.length ? this.hideItems() : this.showItems();
}

onClickFab(btn) {
    .../* Part to add */
    //else if (btn.id === 9) this.editPdf() /* I have to change this line to open the dialog window */
 }

 editPdf(content: any) {
    ...
    this.modalService.open(content, { centered: true });
 }

Answer №1

To access the modal reference in typescript, you can utilize a ViewChild. Simply add the following code snippet in your typescript file:

@ViewChild('dynamicContent', {static: true}) dynamicContent: TemplateRef<any>;

Once this is set up, you can trigger the modal from the function openModal without needing to pass the reference from the template:

openModal() {
   ...
   this.modalService.open(this.dynamicContent, { centered: true });
}

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

Error Loading Chunks in Angular ThreeJS Application Specifically in Safari

I've been working with ThreeJS in Angular. After compiling and uploading the latest version of my app to the server last week, I encountered the following errors on Mac and iPhone: SyntaxError: Left hand side of operator '=' must be a refere ...

Reimbursement for utilizing SwitchMap in Rxjs within the Angular framework

I'm new to using switchMap for the first time and I am encountering an issue. The console is asking me to return a value, but whenever I try to do so, it doesn't seem to be working properly. @Effect() subData$ = this.actions$.pipe( ofType( ...

Ways to retrieve information from forkJoin

Exploring rxjs for the first time and encountering an issue with forkJoin. In my Angular project, I have a service that combines data from two other services and then returns it to a component. However, when I call this service in my Angular component us ...

Guide to building an Angular circular progress indicator using Scalable Vector Graphics (SVG)

I have designed an angular circular progress bar, but I am facing an issue with making the percentage value dynamic. I have managed to retrieve the dynamic value from an API, but I am unsure of how to implement it in creating a circular progress bar using ...

Is there a way to trigger the click event in the week view of an Angular 2+ calendar?

https://i.sstatic.net/Vx2x8.png HTML Templates <mwl-calendar-week-view [viewDate]="viewDate" [refresh]="refresh" (click)="weekDayClick($event)"> </mwl-calendar-week-view> In the component file weekDayCl ...

Practical steps for programmatically adding or removing md-disable-backdrop in md-sidenav

Can the md-disable-backdrop attribute be removed from HTML? The issue arises when opening the side navigation as the md-sidenav does not have the md-disable-backdrop attribute. After making a selection from the form displayed in the side navigation, I now ...

Encountering CORS policy block when attempting to post data using Geoserver API through Angular

I'm currently working on Angular and I need to integrate the Geoserver API to publish spatial database data. Previously, I successfully used PHP Curl with the API and now I want to incorporate it into my Angular app. It's worth mentioning that ...

How can a component properly accept a class as an input and integrate it with its own classes?

Consider a scenario where a component dynamically assigns values to the class attribute of its host element based on specific runtime conditions. For instance, let's analyze this TextBox component that sets class values depending on the readonly and ...

Utilize a single API to save data to the database and upload files simultaneously

I am looking to streamline the process of saving data in a database and uploading a file using a single API endpoint. I am working with Angular and Spring frameworks: The challenge I am facing is that I currently have two functions in Angular and two func ...

What is the best way to monitor updates made to a function that utilizes firestore's onSnapShot method?

I am currently working with the following function: public GetExercisePosts(user: User): ExercisePost[] { const exercisePosts = new Array<ExercisePost>(); firebase.firestore().collection('exercise-posts').where('created-by&apo ...

Explicit final argument in TypeScript

Is it feasible to define a function in TypeScript 2.7.2 and above with variable parameters, but ensuring that the final parameter has a specific type? I am attempting to craft an ambient TypeScript declaration for a JavaScript library that utilizes functi ...

use ".otherwise" or /** with the latest version of Angular2 Router to redirect non-routes using wildcards

Can anyone provide guidance on using wild cards to route in the new Router when a non functional route is specified? Similar to the .otherwise method in Angular 1.X router or /** in previous beta router. Additionally, any example or Plunker code would be ...

Develop an NPM package by bundling various Angular2 components tailored for a CRUD (Create, Read

I am new to Angular2 and have successfully developed three components for managing employees: create/edit, view, and list. The component selectors are <create-employee>, <view-employee>, <list-employee>. My goal is to create a single npm ...

Have I repeated myself in defining my class properties?

Currently, I'm enhancing my understanding of Typescript with the development of a discord.js bot. However, I have come across a piece of code and I am uncertain about its redundancy: import Discord from 'discord.js'; export default class B ...

What is the process for upgrading TypeScript to the newest version using npm?

My current TypeScript version on my machine is 1.0.3.0 and I am looking to upgrade it to the latest version, which is 2.0. Could someone please guide me on how to accomplish this using npm? ...

Angular module with customizable configurations

I am interested in developing a customizable Angular 9 module with IVY and AOT enabled. In the latest version of Angular, IVY and AOT are automatically activated: npx @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8 ...

Use an input of map<string,string> when passing to an angular component

Trying to pass an input value for a component reuse, but facing the challenge of having to use a "hardcoded" map of strings. Uncertain about how to effectively pass this information: <continue-p [additionalInfo]="{ "myString": "str ...

Tips on managing the issue of "Preflight request response does not meet access control requirements: 'Access-Control-Allow-Credentials' value"

I am attempting to send an HTTP POST request to a web-api2 server running on my localhost. My client is operating on http://localhost:4200, and my server is running on http://localhost/MemoryGameServer/api/Test (Different Origin). Below is my Angular 7 cl ...

Struggling to get the bindings to work in my Angular 2 single-page application template project

I have recently started using the latest SPA template within Visual Studio 2017: https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp.net-core-with-javascriptservices/ The template project is functioning properly. ...

Guide to accessing contact list on Ionic framework

I'm new to using Ionic and I'm trying to access the contact list in my app to display contacts only. Can someone please guide me on how to achieve this? I watched a tutorial on YouTube but the code provided doesn't seem to work. I've ad ...