在自定义fancybox(又名灯箱,对话框)中,我使用插值显示内容。
在服务中,在“开放式”fancybox方法中,我做
open: function(html, $scope) {
var el = angular.element(html);
$compile(el)($scope); // how to know when the $compile is over?
$.fancybox.open(el); // the uncompiled is shown before the compiled
}
问题是对话框中的内容是在$ compile结束之前加载的,所以在不到一秒钟之后我就会用值刷新对话框内容。
plunkr有效,但我想避免在完全编译之前显示“el”:我想在$ compile完成工作后才显示它
有没有办法知道$编译结束的时间,所以我会在之后显示fancybox上的内容?
答案 0 :(得分:1)
你不能将$ scope注入服务,没有什么比单例$ scope更好了。
而不是$compile(el)($scope);
尝试:
var compiledEl = $compile(el);
....
$compile
返回已编译的数据。
作为附注
我会为指令提供服务并将其编译成指令。我认为这是正确的方式。
答案 1 :(得分:0)
我在ngDialog模式和弹出提供程序中遇到了同样的问题。我需要根据高度来定位对话框。但高度取决于编译的DOM。
我最终找到了一个使用$ timeout的解决方案,如该帖子所述:http://blog.brunoscopelliti.com/run-a-directive-after-the-dom-has-finished-rendering/
对于你的代码,它会给出类似的东西:
org.h2.jdbc.JdbcPreparedStatement.setString(int, String)