[英]Re $compile angular directive?
OK I have a Meteor app that is using angular-meteor, I am using blaze to add a template into autoform using textAngular which is just a simple angular directive, 好的,我有一个使用angular-meteor的Meteor应用程序,我使用blaze通过textAngular将模板添加到自动表单中,这只是一个简单的angular指令,
Upon updating the form Meteor/Blaze/Autoform re renders the form programtically which in turn rips out the scope from my custom directive. 更新表单后,Meteor / Blaze / Autoform会以程序方式重新呈现该表单,这反过来又从我的自定义指令中剥夺了范围。
How do I rerender the angular 'textAngular' directive after Autoforms rerenders the form? Autoforms重新呈现表单后,如何重新呈现有角的“ textAngular”指令?
I'm assuming i should be using the Template.NAME.rendered
event which works fine it calls after the rerender but how do I force angular to recompile the directive? 我假设我应该使用
Template.NAME.rendered
事件,在重新渲染后调用它可以正常工作,但是如何强制angular重新编译指令?
You can find the whole package here and my particular attempt at rerenderign here 你可以找到整个包在这里和我在rerenderign特别是企图在这里
Any help is greatly appriciated! 任何帮助都非常感谢!
Chris 克里斯
OK I've done it like so : 好的,我已经这样做了:
Template.autoFormTextAngular.rendered = function () {
if(!$(this.firstNode).hasClass('ta-root')){
// create an injector
var $injector = angular.injector(['ng', 'textAngular']);
// use the injector to kick off your application
// use the type inference to auto inject arguments, or use implicit injection
$injector.invoke(function($rootScope, $compile, $document) {
$compile($document)($rootScope);
$rootScope.$digest();
});
}
}; };
not sure if there is a easier way but hey ho it works... 不知道是否有更简单的方法,但是嘿,它是否有效...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.