[innerHTML]
ディレクティブを使用して簡単に達成できます。
http://plnkr.co/edit/6x04QSKhqbDwPvdsLSL9?p=preview
import {Component, Pipe} from '@angular/core'
@Component({
selector: 'my-app',
template: `
Hello my name is <span [innerHTML]="myName"></span>
`,
})
export class AppComponent {
myName='<strong>Pardeep</strong>';
}
更新:
私はそれがRC.1リリース後にこのように動作しません確認。
のは、それがRC.4下記のようにあなたは、私が知っている
@Component({
selector: 'my-app',
template: `
<div [innerHTML]="myCheckbox"></div>
`,
})
export class AppComponent {
dangerousUrl='<input type="checkbox">';
constructor(sanitizer: DomSanitizationService) {
this.myCheckbox= sanitizer.bypassSecurityTrustHtml(this.dangerousUrl);
}
}
http://plnkr.co/edit/Yexm1Mf8B3FRhNch3EMz?p=preview
を
DomSanitizationService
を使用することができ、どのような場合は、 'がmyName = '<入力の場合で動作するようにしましょうタイプ= "チェックボックス"> '; '? –これは 'DomSanitizationService' APIで動作します。 – micronyks
innerHTMLはまだ機能していますが、本当に本当に持っていなければhtmlを信頼したくありません。「コンテンツセキュリティ」のドキュメントをご覧ください https://angular.io/docs/ts/latest/guide/template- syntax.html#!#other-bindings – Thibs