본문으로 바로가기

[AngularJS] ng-bind-html

category Helloworld!/Angular 2018. 5. 8. 14:40

Angular 에서 view 에 데이터를 binding 할 때 mustache 를 사용해서 binding  하는 경우

ex)

<div class="main" ng-contoller="tempController as tc">
   <span>{{tc.str}}</span>
</div>
그리고 데이터에 html 코드가 있는 경우

ex)

public var str = "hello <br/> world! <br/> :)"
mustache 를 사용하면 string 으로 받아들여서 출력시 pre 태그 안에 출력시킨것 처럼 html 코드가 그대로 출력되지만

ex)  결과물 : hello <br/> world! <br/> :)


다음과 같이 ng-bind-html 을 쓰면 html 태그가 적용된채로 화면에 출력 시킬수 있다.
<div class="main" ng-contoller="tempController as tc">
   <span ng-bind-hmtl="tc.str"></span>
</div>