Is it possible to conceal dom elements within an ng-template?

Utilizing ng-bootstrap, I am creating a Popover with HTML and bindings. However, the ng-template keeps getting recreated every time I click the button, causing a delay in the initialization of my component. Is there a way to hide the ng-template instead?

Note: English is not my native language, so please forgive any confusion.

I have attempted using ng-container, but ngbPopover seems to only accept ng-template.

<button type="button" class="card tools-toc btn btn-outline-primary"
    #popover="ngbPopover" [ngbPopover]="popLegend" [ngClass]="{'active': popover.isOpen()}"
    placement="top" [autoClose]="false" popoverClass="popover-legend" (click)="toggleToc()">
    <i class="fas fa-layer-group"></i>
  </button>

<ng-template #popLegend>
  <div>
    <div class="legend-title">Data Layers</div>
    <div >
      <app-core-toc [config]="_configService[1]" [omElec]="true">
      </app-core-toc>
      <app-core-toc [config]="_configService[0]" [omWork]="true">
      </app-core-toc>
    </div>
  </div>
</ng-template>

My goal is to initialize app-core-toc on load and then simply hide or show the template when the button is clicked.

Answer №1

Investigate the ng-bootstrap source code - currently, in version 5.1.0, it consistently generates an embedded view. This behavior may be subject to change down the line. If you have suggestions for enhancing this functionality, don't hesitate to share them on https://github.com/ng-bootstrap/ng-bootstrap/issues

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

Using Angular and RxJS5 to refresh data from both HTTP requests and sockets

Here's a specific scenario I need to address: Retrieve route parameters Utilize route parameters to make an HTTP service call Upon receiving a response from the HTTP service, use the same route parameters to invoke a socket service Whenever the sock ...

Circular reference in Angular/TypeScript

I encountered a circular dependency issue in my Angular project and tried various solutions, including exporting all dependent classes from a "single file" as suggested here. Unfortunately, this approach did not work for me. I then explored other solutions ...

Angular 2: Executing a function after ngFor has completed

Within Angular 1, I crafted a personalized directive called "repeater-ready" to pair with ng-repeat for triggering a callback method upon completion of an iteration: if ($scope.$last === true) { $timeout(() => { $scope.$parent.$parent.$ ...

What is the best way to increase the height of an image beyond the limits of its container, causing it to overlap with other elements

My challenge involves creating a horizontal scrolling list of movie posters. I want the posters to grow in size when hovered over, expanding outside of their container and overlapping other elements. I attempted to use 'position: absolute' on the ...

The Angular component seems to be failing to refresh the user interface despite changes in value

Recently, I created a simple component that utilizes a variable to manage its state. The goal is to have the UI display different content based on changes in this variable. To test this functionality, I implemented the component and used a wait function to ...

Using Private and Protected Methods in Typescript with React: Best Practices

Currently, I am engrossed in developing a React application utilizing Typescript. In cases where a component needs to offer functionality through a reference, I typically incorporate a public method (public focus() : void {...}). However, I find myself pon ...

The type of 'username' cannot be determined without specifying the reference to '@angular/forms/forms' in the node modules

I'm encountering an issue with my application: forgot-password.component.ts(44,7): error TS2742: The inferred type of 'username' cannot be named without a reference to '.../node_modules/@angular/forms/forms'. This is likely not po ...

Having trouble downloading both an HTML file and a PDF file at the same time by clicking two separate buttons in an Angular 8 web API controller

I am encountering an issue with downloading files from my web application. I have two buttons - one for downloading a PDF file and another for downloading an HTML file. The problem arises when clicking on the link to download the HTML file first, as it do ...

Utilizing Angular's Dependency Injection to Provide Services to External Libraries

I'm currently developing an NPM package that enhances the functionalities of Material Datatable. One standout feature is the ability to specify a method that will be triggered when a user clicks on a specific cell. Here is how the property is defined ...

Issues with connecting to server through Angular websocket communication

I deployed the server on an Amazon AWS virtual machine with a public IP address of 3.14.250.84. I attempted to access it using Angular frontend like so: public establishWebSocketConnection(port : number){ this.webSocket = new WebSocket('ws://3.14.250. ...

What causes a hyperlink to take longer to load when using href instead of routerLink in Angular 2+?

As I work on my web application using angular 2 and incorporating routes, I noticed a significant difference in loading speed based on how I link to another component. Initially, being new to angular, I used the href attribute like this: <a href="local ...

Using generics in Typescript, transform an array of strings into various types and values

Enhanced with coding norms I have obtained an array of fruit values: const fruitsArray = ["apple", "banana", "peach"] as const; Utilizing this array as a foundation, I generated types and values in the following manner: type ...

Transferring data to a different module

I'm currently working on an Angular program where I am taking a user's input of a zip code and sending it to a function that then calls an API to convert it into latitude and longitude coordinates. Here is a snippet of the code: home.component.h ...

I am having trouble initializing npm due to an error

I am currently working on a Node.js project but I am having trouble starting Node.js. In my existing Angular project, and after creating a new project with the following commands: sudo npm install -g @angular/cli After that, run: ng new mean-angular5 ...

I'm confused by the function: "sort((a: Article, b: Article) => b.votes - a.votes);"

I'm having trouble grasping the concept of the return statement in sortedArticles(). Can anyone provide me with a resource or explain how this sorting function works? sortedArticles(): Article[] { return this.articles.sort((a: Article, b: Article ...

Transmitting occasional feedback from ASP.NET Web API function to jQuery AJAX

I am currently working on a project that requires sending intermittent status responses from a Web API method back to a jQuery AJAX call in order to display progress in the UI. The process involves the jQuery AJAX calling the Web API method with specific ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...

Issue with Angular Routing When Deployed

After developing a website utilizing Angular 6 and hosting it on GitHub, I incorporated Routing to automatically direct users to the '/home' page instead of the main '/' page. You can access the project by clicking on this project link. ...

Incorrectly calling Asset URL in a single spa micro front-end

Currently, I am utilizing the single-spa library to implement micro front-end functionality. My challenge lies in using assets within my pages as the generated URLs for fetching these assets are incorrect. For example, when attempting to use an informati ...

Is there a way to include lazy loaded components in the production dist folder using angular-cli bundling?

For my development using angular-cli, I have executed the following commands and codes to construct my project. npm install angular-cli (angular-cli: 1.0.0-beta.10) ng new my-app ng g component lazy-me Then, I included a file named app.router.ts with t ...