Skip to main content

Posts

Showing posts from November, 2016

Maintaining Multi-line text format in AngularJS View

I was using AngularJS framework in SharePoint site and was trying to fetch data from a List and display using AngularJS view. The List had Multiple Lines of Text column with Rich Text enabled. The HTML markup looked like this: <p>{{description}}</p> Here description contains value from multi-line text field. However, it trims the HTML part and display only plain text. I even tried using ng-bind-html as: <p ng-bind-html="description"></p> This also didn't solve the problem. This is where Angular filter came to the rescue. Solution: First we need to create a filter: var myApp = angular.module('myApp', ['ngSanitize']);  myApp.filter('trusted', function($sce){     return $sce.trustAsHtml; }); Note that, with this filter we are returning the HTML as trusted. Now, this filter should be used in the HTML: <p ng-bind-html="description | trusted"></p> This would keep the format intact