Issue 1:
I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Currently when you use NgComponentOutlet you cant access created component for "binding". So it can be used only for displaying dynamic components, but not for interaction with them.

Expected behavior

It would be nice to have option how to retrieve created component instance from this directive.

What is the motivation / use case for changing the behavior?

Be able to use dynamic declarative component creation with full access to created component for "binding".

Suggested solution

There are two possible ways as far as i see it :).

I. Use of Output

first change directive to generic

export class NgComponentOutlet<TComponent> implements OnChanges, OnDestroy

then add

@Output()
public ngComponentOutletCreated: EventEmitter<TComponent> = new EventEmitter<TComponent>();

and after component has been created by _viewContainerRef.createComponent emit new component.

II. Add exportAs and public getter for instance of Component

first change directive to generic and add exportAs

@Directive({selector: '[ngComponentOutlet]', exporAs: 'ngComponentOutlet'})
export class NgComponentOutlet<TComponent> implements OnChanges, OnDestroy

then add public getter

public get component(): TComponent
{
if(!this._componentRef)
{
return null;
}

return this._componentRef.instance;
}

Or implement both solutions, because they can work together well.

Both of these solutions are working, but you cant use <ng-container *ngComponentOutlet="comp"> syntax, since i havent figured out how to use "output" binding for *ngComponentOutlet or how to use #myComponent="ngComponentOutlet" with this syntax.

I had to change it to <ng-template [ngComponentOutlet]="comp"> and you can then use "output" binding and also reference with "exportAs" for obtaining directive using ViewChild.

Thank you

Please tell us about your environment:

Windows 10, VSCode 1.11.1

Angular version: 4.0.1

Browser: [all]

Language: [TypeScript 2.2.1]

Issue 2:
I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

There is no way to set @inputs or subscribe to @output events of the Component created by NgComponentOutlet.

Expected behavior

I expect some to set values and to subscribe events.

What is the motivation / use case for changing the behavior?

At least, we should have the same level of functionality as ViewContainerRef.createComponent() which is roughly the programatic equivalent of NgComponentOutlet. That function returns a ComponentRef<any> which provides an instance property that allows direct access to the class instance of the Component. The original feature request for NgComponentOutlet defined an event on the directive that would fire and pass this ComponentRef object after creation. This did not make it into the current implementation and I see no other alternatives to access inputs/outputs.

Supporting only Components with no inputs or outputs severely limits the usefulness of NgComponentOutlet.

Angular version: 4.0.0-rc.1