【问题标题】:Re $compile angular directive?重新 $compile 角度指令?
【发布时间】:2015-08-27 07:48:19
【问题描述】:

好的,我有一个使用 angular-meteor 的 Meteor 应用程序,我正在使用 blaze 使用 textAngular 将模板添加到 autoform,这只是一个简单的 angular 指令,

在更新表单时 Meteor/Blaze/Autoform 重新以编程方式呈现表单,这反过来又从我的自定义指令中删除了范围。

如何在 Autoforms 重新呈现表单后重新呈现 angular 'textAngular' 指令?

我假设我应该使用 Template.NAME.rendered 事件,它在重新渲染后调用它可以正常工作,但我如何强制 angular 重新编译指令?

你可以找到整个包here 和我在重新渲染的特别尝试here

非常感谢任何帮助!

克里斯

【问题讨论】:

    标签: javascript angularjs meteor angular-meteor


    【解决方案1】:

    好的,我已经这样做了:

    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();
        });
      }
    

    };

    不确定是否有更简单的方法,但嘿嘿,它可以工作......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-20
      • 2016-05-05
      • 2016-03-24
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      相关资源
      最近更新 更多