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

177
Views
Angular 2 cómo compilar una plantilla y guardar el resultado html

Ok, ahora tengo que crear un cuerpo para un correo electrónico.

Necesito tomar una plantilla, interpolarla con los datos que ya tengo (objeto js) y tener esta cadena html resultante en una variable , para poder enviar este cuerpo a un servidor que realmente enviará el correo electrónico.

No estoy seguro de usar otro motor de plantillas, manillares por ejemplo, para generar este html.

¿Hay alguna manera de usar el motor de plantilla angular 2? Tenga en cuenta que no necesito mostrarlo, quiero mantenerlo solo en la memoria.

Si no puedo usarlo, ¿qué debo usar? ¿Hay algún enfoque más conocido o recomendado?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No estoy seguro de por qué lo necesita, pero aquí hay algunas ideas:

 import {Component, NgModule, Input, VERSION, ChangeDetectorRef} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' import {Injectable, ComponentFactoryResolver, ApplicationRef, Injector} from '@angular/core'; @Component({ selector:'my-cmp', template: 'here is {{title}}' }) export class MyComponent { @Input() title: string; } @Component({ selector: 'my-app', template: ` <input #inp> <button (click)="create(inp.value)">Create</button> `, }) export class App { constructor(private componentFactoryResolver: ComponentFactoryResolver, private appRef: ApplicationRef, private injector: Injector) { } create(title) { let factory = this.componentFactoryResolver.resolveComponentFactory(MyComponent); let ref = factory.create(this.injector); ref.instance.title = title; this.appRef.attachView(ref.hostView); console.log(ref.location.nativeElement); this.appRef.detachView(ref.hostView); } } @NgModule({ imports: [ BrowserModule ], declarations: [ App , MyComponent], entryComponents: [MyComponent], bootstrap: [ App ] }) export class AppModule {}
over 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!