
committed by
Jason Aden

parent
ca0a55f4ee
commit
2ac2ab7ff6
@ -34,14 +34,14 @@ interface Thenable<T> {
|
||||
* Let's assume that you have an Angular component called `ng2Heroes` that needs
|
||||
* to be made available in AngularJS templates.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng2-heroes"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng2-heroes"}
|
||||
*
|
||||
* We must create an AngularJS [directive](https://docs.angularjs.org/guide/directive)
|
||||
* that will make this Angular component available inside AngularJS templates.
|
||||
* The `downgradeComponent()` function returns a factory function that we
|
||||
* can use to define the AngularJS directive that wraps the "downgraded" component.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng2-heroes-wrapper"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng2-heroes-wrapper"}
|
||||
*
|
||||
* @param info contains information about the Component that is being downgraded:
|
||||
*
|
||||
|
@ -26,21 +26,21 @@ import {INJECTOR_KEY} from './constants';
|
||||
* that will be part of the upgrade application. For example, let's assume we have
|
||||
* defined `HeroesService`
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng2-heroes-service"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng2-heroes-service"}
|
||||
*
|
||||
* and that we have included this in our upgrade app `NgModule`
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng2-module"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng2-module"}
|
||||
*
|
||||
* Now we can register the `downgradeInjectable` factory function for the service
|
||||
* on an AngularJS module.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="downgrade-ng2-heroes-service"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="downgrade-ng2-heroes-service"}
|
||||
*
|
||||
* Inside an AngularJS component's controller we can get hold of the
|
||||
* downgraded service via the name we gave when downgrading.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="example-app"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="example-app"}
|
||||
*
|
||||
* @param token an `InjectionToken` that identifies a service provided from Angular.
|
||||
*
|
||||
|
@ -17,7 +17,86 @@ import {angular1Providers, setTempInjectorRef} from './angular1_providers';
|
||||
import {NgAdapterInjector} from './util';
|
||||
|
||||
|
||||
/** @experimental */
|
||||
/**
|
||||
* <!-- TODO(gkalpak): Add link to guide. -->
|
||||
*
|
||||
* @description
|
||||
*
|
||||
* A helper function for creating an AngularJS module that can bootstrap an Angular module
|
||||
* "on-demand" (possibly lazily) when a {@link downgradeComponent downgraded component} needs to be
|
||||
* instantiated.
|
||||
*
|
||||
* *Part of the [upgrade/static](api?query=upgrade/static) library for hybrid upgrade apps that
|
||||
* support AoT compilation.*
|
||||
*
|
||||
* It allows loading/bootstrapping the Angular part of a hybrid application lazily and not having to
|
||||
* pay the cost up-front. For example, you can have an AngularJS application that uses Angular for
|
||||
* specific routes and only instantiate the Angular modules if/when the user visits one of these
|
||||
* routes.
|
||||
*
|
||||
* The Angular module will be bootstrapped once (when requested for the first time) and the same
|
||||
* reference will be used from that point onwards.
|
||||
*
|
||||
* `downgradeModule()` requires either an `NgModuleFactory` or a function:
|
||||
* - `NgModuleFactory`: If you pass an `NgModuleFactory`, it will be used to instantiate a module
|
||||
* using `platformBrowser`'s {@link PlatformRef#bootstrapModuleFactory bootstrapModuleFactory()}.
|
||||
* - `Function`: If you pass a function, it is expected to return a promise resolving to an
|
||||
* `NgModuleRef`. The function is called with an array of extra {@link StaticProvider Providers}
|
||||
* that are expected to be available from the returned `NgModuleRef`'s `Injector`.
|
||||
*
|
||||
* `downgradeModule()` returns the name of the created AngularJS wrapper module. You can use it to
|
||||
* declare a dependency in your main AngularJS module.
|
||||
*
|
||||
* {@example upgrade/static/ts/lite/module.ts region="basic-how-to"}
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* Apart from `UpgradeModule`, you can use the rest of the `upgrade/static` helpers as usual to
|
||||
* build a hybrid application. Note that the Angular pieces (e.g. downgraded services) will not be
|
||||
* available until the downgraded module has been bootstrapped, i.e. by instantiating a downgraded
|
||||
* component.
|
||||
*
|
||||
* <div class="alert is-important">
|
||||
*
|
||||
* You cannot use `downgradeModule()` and `UpgradeModule` in the same hybrid application.<br />
|
||||
* Use one or the other.
|
||||
*
|
||||
* </div>
|
||||
*
|
||||
* ### Differences with `UpgradeModule`
|
||||
*
|
||||
* Besides their different API, there are two important internal differences between
|
||||
* `downgradeModule()` and `UpgradeModule` that affect the behavior of hybrid applications:
|
||||
*
|
||||
* 1. Unlike `UpgradeModule`, `downgradeModule()` does not bootstrap the main AngularJS module
|
||||
* inside the {@link NgZone Angular zone}.
|
||||
* 2. Unlike `UpgradeModule`, `downgradeModule()` does not automatically run a
|
||||
* [$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest) when changes are
|
||||
* detected in the Angular part of the application.
|
||||
*
|
||||
* What this means is that applications using `UpgradeModule` will run change detection more
|
||||
* frequently in order to ensure that both frameworks are properly notified about possible changes.
|
||||
* This will inevitably result in more change detection runs than necessary.
|
||||
*
|
||||
* `downgradeModule()`, on the other side, does not try to tie the two change detection systems as
|
||||
* tightly, restricting the explicit change detection runs only to cases where it knows it is
|
||||
* necessary (e.g. when the inputs of a downgraded component change). This improves performance,
|
||||
* especially in change-detection-heavy applications, but leaves it up to the developer to manually
|
||||
* notify each framework as needed.
|
||||
*
|
||||
* <div class="alert is-helpful">
|
||||
*
|
||||
* You can manually trigger a change detection run in AngularJS using
|
||||
* [scope.$apply(...)](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply) or
|
||||
* [$rootScope.$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest).
|
||||
*
|
||||
* You can manually trigger a change detection run in Angular using {@link NgZone#run
|
||||
* ngZone.run(...)}.
|
||||
*
|
||||
* </div>
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function downgradeModule<T>(
|
||||
moduleFactoryOrBootstrapFn: NgModuleFactory<T>|
|
||||
((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>)): string {
|
||||
|
@ -42,12 +42,12 @@ class Bindings {
|
||||
* Let's assume that you have an AngularJS component called `ng1Hero` that needs
|
||||
* to be made available in Angular templates.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng1-hero"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng1-hero"}
|
||||
*
|
||||
* We must create a `Directive` that will make this AngularJS component
|
||||
* available inside Angular templates.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng1-hero-wrapper"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper"}
|
||||
*
|
||||
* In this example you can see that we must derive from the `UpgradeComponent`
|
||||
* base class but also provide an {@link Directive `@Directive`} decorator. This is
|
||||
@ -95,7 +95,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
* Instead you should derive a new class from this one and call the super constructor
|
||||
* from the base class.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng1-hero-wrapper" }
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper" }
|
||||
*
|
||||
* * The `name` parameter should be the name of the AngularJS directive.
|
||||
* * The `elementRef` and `injector` parameters should be acquired from Angular by dependency
|
||||
|
@ -107,17 +107,17 @@ import {NgAdapterInjector} from './util';
|
||||
*
|
||||
* Import the `UpgradeModule` into your top level {@link NgModule Angular `NgModule`}.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region='ng2-module'}
|
||||
* {@example upgrade/static/ts/full/module.ts region='ng2-module'}
|
||||
*
|
||||
* Then inject `UpgradeModule` into your Angular `NgModule` and use it to bootstrap the top level
|
||||
* [AngularJS module](https://docs.angularjs.org/api/ng/type/angular.Module) in the
|
||||
* `ngDoBootstrap()` method.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region='bootstrap-ng1'}
|
||||
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng1'}
|
||||
*
|
||||
* Finally, kick off the whole process, by bootstraping your top level Angular `NgModule`.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region='bootstrap-ng2'}
|
||||
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
|
||||
*
|
||||
* {@a upgrading-an-angular-1-service}
|
||||
* ### Upgrading an AngularJS service
|
||||
@ -127,17 +127,17 @@ import {NgAdapterInjector} from './util';
|
||||
*
|
||||
* Let's say you have an AngularJS service:
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="ng1-title-case-service"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="ng1-title-case-service"}
|
||||
*
|
||||
* Then you should define an Angular provider to be included in your `NgModule` `providers`
|
||||
* property.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="upgrade-ng1-service"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="upgrade-ng1-service"}
|
||||
*
|
||||
* Then you can use the "upgraded" AngularJS service by injecting it into an Angular component
|
||||
* or service.
|
||||
*
|
||||
* {@example upgrade/static/ts/module.ts region="use-ng1-upgraded-service"}
|
||||
* {@example upgrade/static/ts/full/module.ts region="use-ng1-upgraded-service"}
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
|
Reference in New Issue
Block a user