Using TypeScript to implement Angular Draggable functionality within an ng-template

Sorry if this question has been asked before, but I couldn't find any information. I am trying to create a Bootstrap Modal popup with a form inside and I want it to be draggable. I have tried using a simple button to display an ng-template on click, but I am having trouble dragging the contents when using angular2-draggable. However, if I remove the ng-template and just use a normal div, dragging works fine.

<button type="button" class="btn btn-outline-primary" (click)="open(testDialog)">TestDrag</button>

    <ng-template #testDialog let-modal>
      <div ngDraggable>
        <div
          class="
            modal-header
            row
            d-flex
            justify-content-between
            mx-1 mx-sm-3
            mb-0
            pb-0
            border-0
          "
        >
          <h3 class="modal-title">Asset</h3>
          This is the header
          <button type="button" class="close" aria-label="Close">
            <span aria-hidden="true"&g;;×</span>
          </button>
        </div>
        <div class="modal-body">This is the body</div>
        <div class="modal-footer">This is the footer</div>
      </div>
    </ng-template>
   

If I take out the ng-template and use a regular div, dragging works perfectly. Can someone please advise on how to make it work under ng-template?

EDIT: Below is the code for the open method located in irgraph.component.ts file

open(content: any) {
          this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title', centered: true}).result.then((result) => {
              this.closeResult = `Closed with: ${result}`;
          }, (reason) => {
              this.closeResult = `Dismissed ${IRGraphComponent.getDismissReason(reason)}`;
          });
      }
   

Answer №1

After receiving advice from @E.Maggini, I made the switch from ng-template to Div and it appears to be functioning properly now. I followed the recommendations outlined in Angular 2 Draggable

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

drop down menu in navigation bar: unable to display items

I am having trouble with a dropdown menu in my code. Even though I used the code from the official Bootstrap website, the items are not appearing in the dropdown list. <nav class="navbar navbar-expand-lg navbar-dark bg-primary "> ...

The collaboration between an object literal declaration and an object instantiated through a constructor function

If I declare let bar: Bar; and set it to initialFooConfig;, is bar still considered as type Bar and an object, or does it become an object in literal notation? If the assignment can be done both ways (assuming initialFooConfig is not a constant), what set ...

Notifying locally in Ionic 3 every couple of hours

I have a concept for my app where users can choose to receive notifications every 3 hours. The challenge is setting up a toggle on the HTML that, when activated, prompts the user to input the first time they eat in a day. From there, the app will send remi ...

Identify and handle errors effectively using TypeScript

I have a question regarding my Express server setup. Here is the code snippet: import express from "express"; import helmet from "helmet"; import cors from "cors"; const app = express(); app.use(helmet()); app.use(cors()); a ...

Dialog in Angular Material refuses to close even after calling the dialog.close() function

I've been struggling with this issue for a while, hoping someone can assist. In my Angular project, I have a login component with a dialog that opens a new popup window. Upon successful login, this window closes and triggers the following function: l ...

Navigating through JSON data in an Angular application

I am currently facing an issue with uploading and parsing a JSON file in my Angular application. The problem lies in the fact that even though I can successfully upload the file, I am unable to access the data from it. To ensure the correct file is being ...

Transform the IO type to an array of Either in functional programming with the fp-ts

Looking for assistance with implementing this in fp-ts. Can someone provide guidance? const $ = cheerio.load('some text'); const tests = $('table tr').get() .map(row => $(row).find('a')) .map(link => link.attr(&apos ...

Show a table row based on a specific condition in Angular

I'm having this issue with the tr tag in my code snippet below: <tr *ngFor="let data of list| paginate:{itemsPerPage: 10, currentPage:p} ; let i=index " *ngIf="data.status=='1'" > <td> </td> <td> ...

Proper management of setTimeout in an Angular application

I am working on a one-page web application where the main component's ngOnInit() function triggers a recursive function called loopDoSomething() using setTimeout: ngOnInit(): void { // Perform some operations this.loopDoSomething(); } loopDoSome ...

How can we use the Vertx router in Quarkus to automatically redirect all unknown routes to index.html?

I have a unique setup with my Quarkus application where I package an Angular SPA within the JAR file. The backend API routes are provided by Quarkus for the front end to consume. During the build process of the Quarkus application, the Angular application ...

Having trouble executing Angular e2e tests above version 2 with protractor while using a proxy

Seeking assistance and guidance! Operating on a Windows system Globally installed Protractor Version 5.3.0 Ran webdriver-manager clean before updating webdriver Updated version with the following command: webdriver-manager update --ie32 --proxy ...

Simulate asynchronous function in imported module

Is it possible to monitor the behavior of an asynchronous function in a module that has been imported? jest.mock('snowflake-promise'); import { Snowflake } from 'snowflake-promise'; describe('Snowflake', () => { let sn ...

Numerous modules accessible via Angular-cli

I'm currently working on an application using the angular-cli interface. However, I have realized that there are no commands available such as: ng generate module featureModule As a result, I am forced to create modules manually. Can someone advise ...

Steps for deleting an image from a component in Angular before getting a new one from API

In my application, there is a child component responsible for fetching and displaying images from an API on the template. The parent component consists of a list of items, and when a user selects an item from the list, a request is made to the API to retri ...

Saving a picture to your Ionic device

I am currently using the code snippet below to access the device's Photo Library. However, it is returning a base64 encoded string, which has left me feeling unsure of how to proceed with this information. My goal is to save the photo to the applicati ...

Why does my array seem to update only once in the view?

I am currently working on a project that aims to visually represent sorting algorithms, but I have encountered an issue. In order to effectively visualize the sorting process of an algorithm, it is crucial to display every change in the array as the proc ...

Issue with handling http errors and navigating routes in Angular 2

Whenever I check a user's token authentication and encounter a 401 error, I aim to redirect them to the login page. The issue arises when attempting to navigate to the login page within the error catch block. constructor(private http: Http , private ...

NextJS Typescript Layout is throwing errors due to the absence of required props

After following the instructions on https://nextjs.org/docs/basic-features/layouts#with-typescript and making changes to my Home page as well as _app.tsx, I encountered an issue with the layout file Layout.tsx. The provided guide did not include an exampl ...

Validation messages in Angular only display once the form has been reset using the reset

I am having trouble with my form appearing clean without validation error messages after using the reset() function. Initially, my form looks clean as expected: https://i.sstatic.net/HLKPq.png However, if a user clicks the register button and encounters a ...

Is there a way to access the value or key of a JSON property in an Angular template for rendering purposes?

Having trouble displaying the JSON values of certain properties on screen. Utilizing Angular Material table to showcase my JSON response. The code snippet below is responsible for rendering the JSON data: <mat-card-content class="dashboard-card-cont ...