2017-04-26 1 views
0

좋아, 이제 전자 메일 용 본문을 만들어야합니다.각도 2 템플릿을 컴파일하고 결과를 저장하는 방법 html

템플릿을 가져 와서 이미 가지고있는 데이터 (js Object)로 보간하고 변수에 html 문자열을 생성해야합니다. 따라서이 바디를 실제로 보낼 전자 메일을 보낼 수 있습니다 -우편.

이 html을 생성하기 위해 다른 템플릿 엔진, 예를 들어 핸들 바를 사용하는 것은 확실하지 않습니다.

각도 2 템플릿 엔진을 사용할 방법이 있습니까? 나는 그것을 보여줄 필요가 없다는 것을 명심한다, 나는 그것을 단지 기억 속에 유지하고 싶다.

사용하지 않으면 어떻게해야합니까? 거기에 가장 잘 알려진 또는 추천 aprouch 있습니까?

답변

0

확실하지 당신은 몇 가지 아이디어를 필요로하지만, 여기에 이유 :

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 {} 
관련 문제