首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >指令内的指令

指令内的指令
EN

Stack Overflow用户
提问于 2013-06-11 20:20:55
回答 1查看 78关注 0票数 0

使用一个指令来突出显示由一个指令输出的<code>标记来呈现<markdown>标记。

问题是,<code>指令在<markdown>指令运行后从未命中。但是,<code>指令运行在没有从<markdown>指令输出的代码标记上。

Markdown指令

代码语言:javascript
运行
复制
angular.module('App').directive "markdown", ->
  converter = new Showdown.converter()

  scope: true
  restrict: 'E'
  link: (scope, element, attrs) ->
    if attrs.markdown
      scope.$watch attrs.markdown, (newVal) ->
        html = converter.makeHtml(newVal)
        element.html(html)
    else
      redraw = ->
        html = converter.makeHtml(element.text())
        element.html(html)

        #### expecting the code directive to be trigger after this.

      scope.$on "$includeContentLoaded", redraw
      redraw()

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-11 20:51:04

AngularJS不知道从你的标记中编译任何东西。有两种方法可以让这些东西进行编译。一种方法是使用闭锁,但我不认为这对你的使用有用。在您的示例中,您将需要编译来自标记的更改。要做到这一点,您可以使用角的$compile服务。

首先,将$compile服务注入您的指令。然后在设置element.html(html)之后,尝试如下:$compile(element.contents())(scope);

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17053040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档