0

I want to recompile / compile the template of my component. I am loading an external module with $onInit, and things just show up when I navigate somewhere else in the page and then back again to the page that loads the module.

I thought that I maybe could compile the template. Do you know a way how I could do that?


Edit:

If I use compile in my code, nothing happens

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

}

1 Answer 1

2

If the template contents are in a variable "templateContent". You can use the "$compile" service of angular as shown below :

$compile(templateContent)(scope);

Find the example here

Sign up to request clarification or add additional context in comments.

3 Comments

ok... lets say I have a template. I want to $compile that. Where should I add this in my code? Or is it better to create a variable, reference it as my template and then $compile(variable)(scope) ?
You should do it in your directive, as shown in the example link i've given. If you can share a fiddle or a sample code it'd be helpful. If you think my answer has helped you, please mark it as accepted answer so that we can work on other questions.
I also read that I could do $compile in a directive, but I am using a component, no directive...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.