Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Angular 2 ng-template no renderizado en dom dentro del componente

tengo un componente asi

 import {Component, OnInit} from '@angular/core'; import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'details', templateUrl: 'details.component.html', styleUrls: ["./details.component.scss"], }) export class DetailsComponent { constructor( private modalService: NgbModal ) { } open(content) { this.modalService.open(content).result.then((result) => { console.log("closed"); }, (reason) => { console.log("dismissed"); }); } }

el html es, observe el componente emergente en la parte superior

 <popover></popover> <div class="row"> <div class="col"> <table class="table"> <thead> <th>Action</th> </thead> <tbody> <tr> <td> <button (click)="open(popover)"> open </button> </td> </tr> </tbody> </table> </div> </div>

El componente abierto es solo un componente para mostrar html

 import {Component, OnInit} from '@angular/core'; @Component({ selector: 'popover', templateUrl: 'popover.component.html', styleUrls: ["./popover.component.scss"], }) export class PopOverComponent { constructor( ) { } }

y el html para el componente popover

 <ng-template #popover let-c="close" let-d="dismiss"> <div class="modal-header"> <h4 class="modal-title">Modal title</h4> <button type="button" class="close" aria-label="Close" (click)="d('Cross click')"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <p>One fine body&hellip;</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" (click)="c('Close click')">Close</button> </div> </ng-template>

Mi problema es cuando tengo ng-template envuelto alrededor de la prueba, el elemento de prueba h1 no se muestra en el dom. Más explícitamente, ng-template no representa lo que necesito para pasar el #popover a la función open para abrir el popover.

Cuando elimino la plantilla ng, puedo ver la prueba h1. Necesito la plantilla ng para renderizar en el dom y estoy poniendo i en un componente porque hay mucho html en el componente popover.

¿Alguna idea de por qué esto se está comportando de esta manera?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

use <ng-container> en su lugar

https://angular.io/guide/structural-directives#!#ng-container

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!