实际上我正在搜索如何将变量转换为 Html,该变量包含来自 instagram 的嵌入代码。
在我的 Controller 中
instaembed.controler "instaCtrl", ($scope, $http) ->
#instagram embed get example from insta
$http.get ("http://api.instagram.com/oembed?url=http://instagr.am/p/fA9uwTtkSN/")
.success(data) ->
$scope.html = data.html
...
结果为$scope.html
包含一个包含许多 div
的 block 引用和图像
我已经在 View 中测试了它(使用 ngsanitize
),但它仅显示文本而不显示图像。
有人知道如何获得它吗? :D
谢谢你(抱歉我的英语不好)。
最佳答案
您必须使用 Angular 内置的严格上下文转义 $sce
$sce
Documentation
然后,在您的 Controller 中:
instaembed.controler "instaCtrl", ($scope, $http, $sce) ->
#instagram embed get example from insta
$http.get ("http://api.instagram.com/oembed?url=http://instagr.am/p/fA9uwTtkSN/")
.success(data) ->
$scope.html = $sce.trustAsHtml(data.html);
...
关于javascript - angularJs 变量到 Html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31024365/