Angularjs 角度:如何强制块重新编译
我正在对prettify的输出进行后处理,以突出显示代码中的一些行。我使用的代码如下,效果很好:Angularjs 角度:如何强制块重新编译,angularjs,twitter-bootstrap-3,prettify,Angularjs,Twitter Bootstrap 3,Prettify,我正在对prettify的输出进行后处理,以突出显示代码中的一些行。我使用的代码如下,效果很好: x = angular.element('.prettify li:nth-child(' + zz['line'] + ')'); x.css('background-color', 'yellow'); x.prop('title', zz['message']); 现在,我想使用引导工具提示,而不是使用title标记在行上显示消息。上述代码的明显变化是: x.prop('tooltip',
x = angular.element('.prettify li:nth-child(' + zz['line'] + ')');
x.css('background-color', 'yellow');
x.prop('title', zz['message']);
现在,我想使用引导工具提示,而不是使用title标记在行上显示消息。上述代码的明显变化是:
x.prop('tooltip', zz['message']);
然而,这不起作用。我假设我需要告诉Angular重新编译该块,因此它将获取tooltop的指令(因此问题的标题)
更新-这里有一把小提琴,显示了我正在尝试做什么:重新编译thr块-
您应该使用$compile服务,如下所示:
$compile(block)(scope)
但是,对于您的任务,您只需要:
scope.$apply()
以及:
将x.prop
更改为x.attr
如果需要强制angular重新消化某个范围,则只需调用:
$scope.$apply();
这将使$scope重新应用自上次应用以来可能发生的任何更改。仅当创建交互的初始事件来自angular应用程序之外的事件处理程序时,才需要运行这些类型的应用程序
您的另一个选择是拨打:
$scope.$apply(function(){
//put your code in here, and it will run your code and then apply it to the current scope
});
谢谢,但这似乎没用。我在小提琴上添加了一个链接,可以更好地解释事情。谢谢,但这似乎没什么帮助。我在小提琴上添加了一个链接,可以更好地解释事情。