update upgrade-static

This commit is contained in:
Filipe Silva 2016-11-09 19:05:03 +00:00
parent 455f2f6896
commit f958661afe
5 changed files with 47 additions and 39 deletions

View File

@ -48,9 +48,8 @@ describe('Upgrade Tests', function () {
describe('Upgraded static component', function() { describe('Upgraded static component', function() {
beforeAll(function () { beforeAll(function () {
setProtractorToHybridMode();
browser.get('/index-upgrade-static.html'); browser.get('/index-upgrade-static.html');
setProtractorToNg1Mode();
waitForNg1AsyncBootstrap();
}); });
it('renders', function () { it('renders', function () {

View File

@ -1,16 +1,36 @@
import { heroDetail } from './hero-detail.component';
import { ContainerComponent } from './container.component';
import { upgradeAdapter } from './upgrade_adapter';
declare var angular: any; 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', []) angular.module('heroApp', [])
.component('heroDetail', heroDetail) .component('heroDetail', heroDetail)
.directive('myContainer', upgradeAdapter.downgradeNg2Component(ContainerComponent)); .directive('myContainer', downgradeComponent({component: ContainerComponent}));
upgradeAdapter.bootstrap( platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
document.querySelector('hero-app'), let upgrade = platformRef.injector.get(UpgradeModule);
['heroApp'], upgrade.bootstrap(document.body, ['heroApp'], {strictDi: true});
{strictDi: true} });
);

View File

@ -8,6 +8,4 @@ import { Component } from '@angular/core';
<hero-detail></hero-detail> <hero-detail></hero-detail>
` `
}) })
export class ContainerComponent { export class ContainerComponent { }
}

View File

@ -7,3 +7,17 @@ export const heroDetail = {
controller: function() { 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

View File

@ -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';
});