相关疑难解决方法(0)

AngularJS:从字符串中插入HTML

我看了很多,但我要么找不到答案,要么我不明白.一个具体的例子将赢得投票=)

  • 我有一个返回HTML字符串的函数.
  • 我不能改变这个功能.
  • 我希望将字符串表示的html插入到DOM中.
  • 我很高兴使用控制器,指令,服务或其他任何有效的方法(并且是相当不错的做法).
  • 免责声明:我不理解$编译好.

这是我尝试过的:

// My magic HTML string function.
function htmlString (str) {
    return "<h1>" + str + "</h1>";
}

function Ctrl ($scope, $compile) {
  $scope.htmlString = htmlString;
}
Ctrl.$inject = ["$scope", "$compile"];
Run Code Online (Sandbox Code Playgroud)

那没用.

我也试过它作为一个指令:

// My magic HTML string function.
function htmlString (str) {
    return "<h1>" + str + "</h1>";
}

angular.module("myApp.directives", [])
  .directive("htmlString", function () {
    return {
      restrict: "E",
      scope: { content: "@" },
      template: "{{ htmlStr(content) }}"
    }
  });

  ... and in …
Run Code Online (Sandbox Code Playgroud)

html string angularjs

73
推荐指数
2
解决办法
12万
查看次数

如何在 angularjs 中的字符串中创建链接标签?

我有包含链接的字符串,我想让该链接可单击。从角度来看我将如何去做呢?

\n\n

以下是我拥有的 json 数据中的字符串示例“I\xe2\x80\x99m 于 9 月 27 日与 @BillieFaiers 一起主持 #AFF Catwalk Show @Bullring。在此处了解更多信息 > http://www.clickhereformoreinfo.com

\n\n

基本上我希望主题标签、at 符号和链接都是标签。请帮忙解决这个问题几个小时了。

\n

html javascript string json angularjs

2
推荐指数
1
解决办法
3522
查看次数

标签 统计

angularjs ×2

html ×2

string ×2

javascript ×1

json ×1