1. Back To Blog

What is the need of $sce ? ( AngularJS Interview Questions)

In case you are new to Angular I would recommend to start  Angular from basic.

Watch most 25 Important Angular Interview questions and Answer video :-

 "$sce" (Strict Contextual escaping) service helps to render trustful HTML from Angular. By default HTML is not rendered in angular. For example below is a simple angular controller with HTML content in one of its variable.

  

In order to render the above HTML content we have binded the same to the below "DIV" tag. To render HTML content we have used "ng-bind-html" attribute.

 

You would be surprised to know that the above code does not work. If you go to google chrome console (press f12) you would see that it has marked the HTML as unsafe. This is actually a great security feature. This ensures that any unsafe HTML and SCRIPTS are not rendered and executed with out checks.   

 

 To mark the above HTML as safe we have used "trustAsHtml" from the "$sce" service.

  

With Angular server side MVC is also important.

Clear Angular basic concepts with this  latest tutorial for Angular freshers and developers :-


Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social