我创建了一个简单的应用程序(角度1.6),允许用户保存代码并使用prismjs显示代码突出显示。唯一的问题是,当我从指令中调用Prism.highlightAll时,我必须使用angular的$ timeout方法,延迟时间为1秒。
app.directive("markupPanels", function($timeout) {
return {
restrict: "E",
replace: true,
templateUrl: "directives/markupPanel.html",
link: function() {
$timeout(function() {
Prism.highlightAll();
}, 1000)
}
}
然而,浏览器闪烁,我认为必须有更好的方法来实现这一点。
答案 0 :(得分:0)
使用element.ready()
。
link: function($scope, element) {
element.ready(function() {
Prism.highlightElement(element[0]);
});
}
来源:angular-prism。