DynamicComponentLoader is now deprecated and doesn't fire events propely. Use ComponentResolver with ViewContainerRef.
import { Directive , Input, OnInit, ComponentResolver,ViewContainerRef } from '@angular/core'; @Directive({ selector:'[yourSelector]' }) export class YourDirective implements OnInit{ constructor( private resolver:ComponentResolver, private viewContainerRef:ViewContainerRef ){} ngOnInit(){ //Magic! this.resolver.resolveComponent(this.content) .then(cmpFactory => { const injector = this.viewContainerRef.injector; return this.viewContainerRef.createComponent(cmpFactory, 0, injector); }); } } W dniu niedziela, 10 stycznia 2016 05:14:30 UTC+1 użytkownik Jed napisał: > > I know this reply is a little late to the party, however it was one of the > bigger issues that I just faced and overcame and this thread was one of the > top results in google. (Though I understand we're now in a later build of > Angular2) > > I just managed to get a similar functionality to ng-include by using > DynamicComponentLoader > > import {Component, View, DynamicComponentLoader, Injector} from > 'angular2/core'; >> >> //... >> constructor(dynamicComponentLoader:DynamicComponentLoader, >> injector:Injector) { >> dynamicComponentLoader.loadAsRoot(ChildComponentName, >> '#TargetElementID', injector); >> } >> >> > Hope this helps anybody on the same issue. (Angular build used: > Angular2.beta0) > > On Wednesday, August 12, 2015 at 12:31:18 PM UTC+1, Pete Moss wrote: >> >> We are trying to build a metadata-driven UI for our application and we >> are considering using Angular2 to build it. One question we have is that >> we'd like to build a somewhat generic parameter-driven component whose view >> template is dynamically rendered by the server. >> >> I did a proof-of-concept in Angular1 by doing something like this: >> >> <ng-include src="ctrl.template"></ng-include> >> >> where ctrl.template is a controller var specifying a URL that is >> dynamically set in the controller. This seemed to work for me. But, I >> couldn't get <ng-include> to work at all for me in Angular2. Will this >> technique work in Angular2? >> >> Is there any way to dynamically inject view code into an Angular2 >> component? >> >> Thanks, >> Pete >> >> >> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.