24
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AngularJS:文字列をエスケープさせずに出力する方法

Last updated at Posted at 2014-10-17

※AngularJSバージョン:1.3

テンプレ側とJS側それぞれに対応が必要

  • html側: ng-bind-htmlディレクティブを使用
  • JS側: $sce.trustAsHtmlを使用
<div ng-bind-html="content"></div>
app = angular.module('myApp', []);
app.controller 'MainCtrl', ($scope, $sce) ->
	html = "<p>hoge</p>"
  	$scope.content = $sce.trustAsHtml(html)

angular-sanitizeモジュールを使用する場合はJS側の$sce.trustAsHtmlが不要

app = angular.module('myApp', ['ngSanitize']);
app.controller 'MainCtrl', ($scope) ->
	html = "<p>hoge</p>"
  	$scope.content = html

詳しくは↓

24
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?