From f958661afeadb98f23d7b181b888ec5bb588c8e9 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Wed, 9 Nov 2016 19:05:03 +0000 Subject: [PATCH] update upgrade-static --- .../_examples/upgrade-adapter/e2e-spec.ts | 3 +- .../ts/app/upgrade-static/app.module.ts | 42 ++++++++++++++----- .../app/upgrade-static/container.component.ts | 4 +- .../upgrade-static/hero-detail.component.ts | 14 +++++++ .../ts/app/upgrade-static/upgrade_adapter.ts | 23 ---------- 5 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/upgrade_adapter.ts diff --git a/public/docs/_examples/upgrade-adapter/e2e-spec.ts b/public/docs/_examples/upgrade-adapter/e2e-spec.ts index fe85745026..17c36edaed 100644 --- a/public/docs/_examples/upgrade-adapter/e2e-spec.ts +++ b/public/docs/_examples/upgrade-adapter/e2e-spec.ts @@ -48,9 +48,8 @@ describe('Upgrade Tests', function () { describe('Upgraded static component', function() { beforeAll(function () { + setProtractorToHybridMode(); browser.get('/index-upgrade-static.html'); - setProtractorToNg1Mode(); - waitForNg1AsyncBootstrap(); }); it('renders', function () { diff --git a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/app.module.ts b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/app.module.ts index 7e672c888c..3e0641f152 100644 --- a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/app.module.ts +++ b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/app.module.ts @@ -1,16 +1,36 @@ -import { heroDetail } from './hero-detail.component'; -import { ContainerComponent } from './container.component'; -import { upgradeAdapter } from './upgrade_adapter'; - - declare var angular: any; +import { NgModule } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { BrowserModule } from '@angular/platform-browser'; +import { UpgradeModule, downgradeComponent } from '@angular/upgrade/static'; + +import { heroDetail, HeroDetailComponent } from './hero-detail.component'; +import { ContainerComponent } from './container.component'; + +// #docregion heroupgrade +@NgModule({ + imports: [ + BrowserModule, + UpgradeModule + ], + declarations: [ + ContainerComponent, + HeroDetailComponent + ], + entryComponents: [ + ContainerComponent + ] +}) +export class AppModule { + ngDoBootstrap() {} +} +// #enddocregion heroupgrade angular.module('heroApp', []) .component('heroDetail', heroDetail) - .directive('myContainer', upgradeAdapter.downgradeNg2Component(ContainerComponent)); + .directive('myContainer', downgradeComponent({component: ContainerComponent})); -upgradeAdapter.bootstrap( - document.querySelector('hero-app'), - ['heroApp'], - {strictDi: true} -); +platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => { + let upgrade = platformRef.injector.get(UpgradeModule); + upgrade.bootstrap(document.body, ['heroApp'], {strictDi: true}); +}); diff --git a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/container.component.ts b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/container.component.ts index 1e3ebf509b..c28e5ea42d 100644 --- a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/container.component.ts +++ b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/container.component.ts @@ -8,6 +8,4 @@ import { Component } from '@angular/core'; ` }) -export class ContainerComponent { - -} +export class ContainerComponent { } diff --git a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/hero-detail.component.ts b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/hero-detail.component.ts index 862c904bbc..874d414509 100644 --- a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/hero-detail.component.ts +++ b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/hero-detail.component.ts @@ -7,3 +7,17 @@ export const heroDetail = { controller: function() { } }; + +// #docregion heroupgrade +import { Directive, ElementRef, Injector } from '@angular/core'; +import { UpgradeComponent } from '@angular/upgrade/static'; + +@Directive({ + selector: 'hero-detail' +}) +export class HeroDetailComponent extends UpgradeComponent { + constructor(elementRef: ElementRef, injector: Injector) { + super('heroDetail', elementRef, injector); + } +} +// #enddocregion heroupgrade diff --git a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/upgrade_adapter.ts b/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/upgrade_adapter.ts deleted file mode 100644 index c9173347bc..0000000000 --- a/public/docs/_examples/upgrade-adapter/ts/app/upgrade-static/upgrade_adapter.ts +++ /dev/null @@ -1,23 +0,0 @@ -// #docregion -import { UpgradeAdapter } from '@angular/upgrade'; -import { NgModule, forwardRef } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; - -import { ContainerComponent } from './container.component'; - -export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule)); - -// #docregion heroupgrade -const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail'); - -@NgModule({ - imports: [ BrowserModule ], - declarations: [ ContainerComponent, HeroDetail ] -}) -export class AppModule {} -// #enddocregion heroupgrade - -angular.module('heroApp', []) - .controller('MainCtrl', function() { - this.message = 'Hello world'; - });