json字符串中的超链接

时间:2016-02-24 20:27:37

标签: angularjs json

我有一个角度模板将json数据拉入事件日历。有没有办法在json中的字符串中包含url链接,例如:

    { "name" : "Lee Morgan",
      "interviewer":"interviewed by: <a href='http://onehungrymind.com/angularjs-dynamic-templates/'>Sonny Stitt</a>",
      "day" : "Saturday",
      "date": "April 18th",
    },

我之所以需要这样做,是因为我的一些数据有“面试者”变量,有些不这样做 - 请看下图。我想可能包括整个“采访者”行作为占位符,但随后面试官的名字需要被超链接。


enter image description here

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

Angular会在将HTML插入模板时自动转义HTML。您可以使用ng-bind-html来防止这种情况,例如

// In the controller
$scope.myObject = <the JSON object you provided>;

<!-- The view -->
<div ng-bind-html="myObject.interviewer"></div>

来源/相关:AngularJS: Insert HTML from a string

答案 1 :(得分:0)

可以使用ngSanitize并转义链接的双引号。在任何特殊字符的情况下,也可以对网址进行编码,但不是严格要求。

{ "first_name" : "Lee",
    "last_name" : "Morgan",
    "day" : "Saturday",
    "date": "April 18th",
    "stage" : "norris-panel",
    "interviewer":", interviewed by: <a href=\"//onehungrymind.com/angularjs-dynamic-templates\" target=\"_blank\"><u>Art Blakey</u></a>",
    "genre" : "music",
    "work_title" : "Trumpet Dreams",
  "convrs_nmber":"1051",
    "time" : "10:00 am"
},