What it does
Part of the upgrade/static library for hybrid upgrade apps that support AoT compilation
Allows an AngularJS component to be used from Angular.
How to use
Let's assume that you have an AngularJS component called ng1Hero
that needs
to be made available in Angular templates.
We must create a Directive
that will make this AngularJS component
available inside Angular templates.
In this example you can see that we must derive from the UpgradeComponent
base class but also provide an @Directive
decorator. This is
because the AoT compiler requires that this information is statically available at
compile time.
Note that we must do the following:
- specify the directive's selector (
ng1-hero
) - specify all inputs and outputs that the AngularJS component expects
- derive from
UpgradeComponent
- call the base class from the constructor, passing
- the AngularJS name of the component (
ng1Hero
) - the
ElementRef
andInjector
for the component wrapper
- the AngularJS name of the component (
Class Overview
class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
constructor
(name: string, elementRef: ElementRef, injector: Injector)
}
Class Description
A helper class that should be used as a base class for creating Angular directives that wrap AngularJS components that need to be "upgraded".
Constructor
constructor(name: string, elementRef: ElementRef, injector: Injector)
Create a new UpgradeComponent
instance. You should not normally need to do this.
Instead you should derive a new class from this one and call the super constructor
from the base class.
- The
name
parameter should be the name of the AngularJS directive. - The
elementRef
andinjector
parameters should be acquired from Angular by dependency injection into the base class constructor.
Note that we must manually implement lifecycle hooks that call through to the super class.
This is because, at the moment, the AoT compiler is not able to tell that the
UpgradeComponent
already implements them and so does not wire up calls to them at runtime.
exported from upgrade/static/index, defined in upgrade/static/src/static/upgrade_component.ts