2017-04-26 6 views
0

これまでは電子メールの本文を作成する必要がありました。角2テンプレートをコンパイルして結果を保存する方法html

テンプレートを取り込み、すでに持っているデータ(jsオブジェクト)で補間し、変数にhtml文字列を挿入する必要があります。このボディを実際に送信するサーバーに送ることができます-郵便物。

このhtmlを生成するために、例えば、他のテンプレートエンジン、ハンドルバーを使用することについてはわかりません。

角度2のテンプレートエンジンを使用する方法はありますか?私はそれを示す必要はないことを覚えておいてください。私はそれを記憶の中にだけ残したいと思います。

私は何を使用すればよいですか?最もよく知られているか推奨されていますか?

答えて

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 {} 
関連する問題