javascript - angularJs 变量到 Html

标签 javascript html angularjs coffeescript instagram

实际上我正在搜索如何将变量转换为 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/

相关文章:

angularjs - 如何将 HTML 传递给 Angular 指令?

javascript - 如何从 HTML 文本中生成 DOM 对象

JavaScript -Change CSS color for 5 seconds - 如何添加缓动效果?

javascript - 从 JSON 获取数据

iphone - 在 SQLite 数据库的 uiwebview 中显示 HTML 文件?

javascript - 从给定文本开始的 Angularjs 过滤器搜索

javascript - HTML 和 JavaScript - 如何正确保存纯文本

javascript - 当浏览器不支持功能时,我如何知道是否存在 polyfill 或 Babel 插件?例如 : accessors

html - 使用 html 在 Telegram Bot 上发送粗体和斜体文本

javascript - 为什么我的 jQuery 脚本无法加载?