1

I'm trying to load a component based off of a variable but I get a "Uncaught Error: Template parse errors". How would I go about doing something like this?

<app-{{ this.plugin.component }}></app-{{ this.plugin.component }}>

2 Answers 2

2

I don't think that is possible to do it on template, but you certainly can do it on your controller/component try to do something like:

var scope = $rootScope.$new();
var element = angular.element('<app' + variable + '></app' + variable + '>');
element = $compile(element)(scope);

To print the element in your template you'll need to use $sce:

How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+

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

Comments

0

Have to add each path manually to the "app.module" but everything seems to operate by using child paths. Wish there was a way to more dynamically use components with the tags but this will work for what I'm doing now.

{
    path: 'mypath', 
    component: MyComponent,
    children: [
      {
        path: 'childpath',
        component: ChildComponent
      }
    ]
}

Comments

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.