Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Angular 2 how to compile a template and save the result html

Ok, by now I have to create a body for an e-mail.

I need to take a template, interpolate it with the data I already have (js Object) and have this resulted html string in a variable, so I can send this body to a server that will actually send the e-mail.

I am not sure about using other template engine, handlebars for instance, to generate this html.

Is there a way to use the angular 2 template engine? Keep in mind that I dont need to show it, I want to keep it in memory only.

If I cant use it what should I use? Is there any best known or recomended aprouch?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Not sure why you need it but here is some 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda