Reputation: 35268
Consider this my json string,
[{
"Mat_id": "2",
"Mat_Name": "Steel",
"Measurement": "mm",
"Description": "Steel"
}]
Can i add HTML Tags inside this json string like this,
[{
"Mat_id": "2",
"Mat_Name": "Steel",
"Measurement": "<bold>mm</bold>",
"Description": "Steel"
}]
I am doing so because i will pass this json object to a yui datatable which consumes json datasource...
EDIT:
This my resulted json string,
{
"Table": [{
"Mat_id": "2",
"Mat_Name": "Jully",
"Measurement": "<bold>Inches</bold>",
"Description": "Gully"
}, ]
}
But i didnt get my Measurement column values in bold...
Upvotes: 9
Views: 42116
Reputation: 4245
This answer is for >Angular 2 compilation regarding parsing json containing html tags.
Below is the json containing html tags
{
"data":"highlighting <b>this</b> in bold"
}
As you can see this is the keyword need to be bold in html while rendering.
If I use angular interpolation like below it will be parsed as normal string and <b> tag will be printed as it is.
<p> {{titleDetails.what}}</p>
output : highlighting <b>this</b> in bold.
But if you use property binding like below it will render the expected output.
<p [innerHTML]="titleDetails.what"></p>
Output: highlighting this in bold
Upvotes: 0
Reputation: 3067
use Encoder.js from http://code.google.com/p/jsool/source/browse/jsool-site/js/util/Encoder.js?r=176
when getting data use
Encoder.htmlDecode(value);
and when passing data use
Encoder.htmlDecode(value);
Upvotes: 1
Reputation: 122624
Technically, yes, you can do that... practically, I'd be a bit concerned if there were HTML markup in my data. What else might be in there? Smells like an XSS vulnerability.
Upvotes: 9