I need to provide view-data to a Component through DynamicComponentLoader
, if possible through the constructor, but for that I need to bind the data.
var bindings = Injector.resolve([bind(Model).toValue(viewModel)]);
this.loader.loadIntoLocation(component, eleRef, anchor, bindings)
This would work, but I need to bind the data into the Injection-System and thus I'm not sure if that is the right way.
another way to set the data is to use the promise:
this.loader.loadIntoLocation(component, eleRef, anchor).then(componentRef=> {
var comp:AbstractComponentBase = componentRef.instance;
comp.model = viewModel;
});
This would also work, but the model is null
(or pseudo value) during initialization and this could be a problem with @ViewChildren
and afterViewInit()
.
Is there another way to provide data to the component created with DynamicComponentLoader
?