【问题标题】:Recompile angularJS component?重新编译angularJS组件?
【发布时间】:2017-02-13 22:37:39
【问题描述】:

我想重新编译/编译我的组件的模板。我正在使用 $onInit 加载一个外部模块,当我在页面中的其他位置导航然后再次返回到加载模块的页面时,事情就会出现。

我想我也许可以编译模板。你知道我该怎么做吗?


编辑:

如果我在我的代码中使用编译,什么都不会发生

controller: {
$onInit(){
this.$ocLazyLoad.load('some.module.js');
 }
},

template:
'<p>Sample text here</p>',

compile: function (tElement, tAttrs) {
    return function(scope) {
        scope.widgetCenter = tAttrs.widgetCenter;
    };

}

【问题讨论】:

    标签: angularjs compilation components


    【解决方案1】:

    如果模板内容在变量“templateContent”中。可以使用angular的“$compile”服务,如下图:

    $compile(templateContent)(scope);
    

    查找示例here

    【讨论】:

    • 好的...假设我有一个模板。我想 $compile 那个。我应该在我的代码中的哪里添加它?还是创建一个变量,将其作为我的模板引用,然后 $compile(variable)(scope) 更好?
    • 您应该在指令中执行此操作,如我提供的示例链接所示。如果您可以分享小提琴或示例代码,那将会很有帮助。如果您认为我的回答对您有所帮助,请将其标记为已接受的答案,以便我们处理其他问题。
    • 我还读到我可以在指令中执行 $compile,但我使用的是组件,没有指令...
    猜你喜欢
    • 2019-04-11
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多