使用一个指令来突出显示由一个指令输出的<code>
标记来呈现<markdown>
标记。
问题是,<code>
指令在<markdown>
指令运行后从未命中。但是,<code>
指令运行在没有从<markdown>
指令输出的代码标记上。
Markdown指令
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()
有什么想法吗?
发布于 2013-06-11 20:51:04
AngularJS不知道从你的标记中编译任何东西。有两种方法可以让这些东西进行编译。一种方法是使用闭锁,但我不认为这对你的使用有用。在您的示例中,您将需要编译来自标记的更改。要做到这一点,您可以使用角的$compile服务。
首先,将$compile
服务注入您的指令。然后在设置element.html(html)
之后,尝试如下:$compile(element.contents())(scope);
https://stackoverflow.com/questions/17053040
复制相似问题