Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to update the html type field in the widget

Naresh291
Tera Contributor

Hi ,

I have a form with a field 'description' which is of HTML type . I want to show the same piece of information(in terms of look n feel- -red , bold , underlined , hyperlinks ) in the widget . 

I have used  <div ng-bind-html="::field name"></div>   in the HTML of the widget , If the value in the 'description' field in the form is bold and in italics , then the same information is shown in the Widget .

But if the value in the description field is written with Red text and with underlined text , then the same is not displayed in the widget in the portal .

Can anyone say what am i missing .

 

Regards,

Naresh

 

 

8 REPLIES 8

Zaib Ali
Tera Contributor

Yes there is the bind html.

 

Here is an example of HTML code:

 

<div ng-bind-html="::data.desc" "></div> (where data.desc is your HTML field that you get in the server part)

 

 

 

and the client side:

 

function($scope, $sce) {

 

  /* widget controller */

 

  var c = this;

 

 

 

// Display HTML field

 

$scope.data.desc = $sce.trustAsHtml($scope.data.desc);

 

 

 

}

 

 

 

Please mark if it's helpful

Hi Zaib,

 

I used the same logic , but it doesnt seem to work , when i am entering the text in Red , or with some underline text.

 

Can you share your code here ?

Hi Zaib,

Server script:

 

data.btnTable = 'x_tab';
var gr = new GlideRecord(data.btnTable);
gr.addActiveQuery();

  while (gr.next()) {
var app = {};

app.desc = gr.description.getDisplayValue();

}

 

HTML Code:

<div ng-bind-html="::app.desc"></div>

 

Client controller:

$scope.app.desc = $sce.trustAsHtml($scope.app.desc);

 

Here's the code