AngularJS:如何知道什么时候$编译完成? [英] AngularJS: how to know when the $compile has finished?
问题描述
http://plnkr.co/edit/GRVZl35D1cuWz1kzXZfF?p=$p$ PVIEW
在自定义的fancybox(又名灯箱,一个对话框)我与展示插值内容。
In the custom fancybox (aka lightbox, a dialog) I show contents with interpolated values.
在服务,在开放的fancybox的方法,我做
in the service, in the "open" fancybox method, i do
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
}
问题是对话框中的内容是$编译结束前,打完不到一秒钟我得到的价值观对话内容的刷新加载。
The problem is that the content in the dialog is loaded before the end of the $compile, so after less than a second i got a refresh of the dialog content with the values.
的plunkr的作品,但我想避免的厄尔尼诺显示之前被完全编译:我想展现$编译完成它只有在他的工作
有没有办法知道什么时候$编译它已经结束了,所以我会在那之后就展现在的fancybox内容?
Is there a way to know when the $compile it's over so i'll show the content on fancybox only after that?
推荐答案
您不能注入$范围到服务,有什么比一个单身$范围。
You can't inject $scope into services, there is nothing like a singleton $scope.
因此,而不是 $编译(EL)($范围内);
尝试:
So instead of $compile(el)($scope);
try:
var compiledEl = $compile(el);
....
编纂的数据的 $编译
的回报。
的作为一个方面说明的
我要提供的服务指令,并编译成指令来代替。我认为这是正确的方式。
I would provide service to directive and compile it into directive instead. I think it's the right way.
这篇关于AngularJS:如何知道什么时候$编译完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!