update upgrade-io example

This commit is contained in:
Filipe Silva 2016-11-10 12:04:19 +00:00
parent f958661afe
commit 2117d40de3
4 changed files with 49 additions and 33 deletions

View File

@ -62,9 +62,8 @@ describe('Upgrade Tests', function () {
describe('Upgraded component with IO', function() {
beforeAll(function () {
setProtractorToHybridMode();
browser.get('/index-upgrade-io.html');
setProtractorToNg1Mode();
waitForNg1AsyncBootstrap();
});
it('has inputs', 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;
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});
});

View File

@ -15,3 +15,20 @@ export const heroDetail = {
};
}
};
import { Directive, ElementRef, Injector, Input, Output, EventEmitter } from '@angular/core';
import { UpgradeComponent } from '@angular/upgrade/static';
import { Hero } from '../hero';
@Directive({
selector: 'hero-detail'
})
export class HeroDetailComponent extends UpgradeComponent {
@Input() hero: Hero;
@Output() deleted: EventEmitter<Hero>;
constructor(elementRef: ElementRef, injector: Injector) {
super('heroDetail', elementRef, injector);
}
}

View File

@ -1,20 +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));
const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');
@NgModule({
imports: [ BrowserModule ],
declarations: [ ContainerComponent, HeroDetail ]
})
export class AppModule {}
angular.module('heroApp', [])
.controller('MainCtrl', function() {
this.message = 'Hello world';
});