forked from angular/angular-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(upgrade): update NgUpgrade with AoT, router, unit tests (#2803)
Followup from #2781
- Loading branch information
1 parent
d0ab5f8
commit 7decccf
Showing
184 changed files
with
2,278 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,3 @@ protractor-helpers.js | |
**/ts/**/*.js | ||
**/js-es6*/**/*.js | ||
**/ts-snippets/**/*.js | ||
!**/systemjs.config.extras.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/*.js | ||
aot/**/* | ||
!aot/bs-config.json | ||
!aot/index.html | ||
!copy-dist-files.js | ||
!rollup-config.js | ||
!systemjs.config.1.js |
12 changes: 12 additions & 0 deletions
12
public/docs/_examples/upgrade-module/ts/src/app/ajs-to-a-providers/ajs-upgraded-providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// #docregion | ||
import { HeroesService } from './heroes.service'; | ||
|
||
export function heroesServiceFactory(i: any) { | ||
return i.get('heroes'); | ||
} | ||
|
||
export const heroesServiceProvider = { | ||
provide: HeroesService, | ||
useFactory: heroesServiceFactory, | ||
deps: ['$injector'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
public/docs/_examples/upgrade-module/ts/src/app/divide-routes/app.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// #docregion | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'my-app', | ||
template: ` | ||
<router-outlet></router-outlet> | ||
<div ng-view></div> | ||
`, | ||
}) | ||
export class AppComponent { } |
62 changes: 62 additions & 0 deletions
62
public/docs/_examples/upgrade-module/ts/src/app/divide-routes/app.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// #docregion | ||
declare var angular: angular.IAngularStatic; | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { UpgradeModule } from '@angular/upgrade/static'; | ||
|
||
import { HeroModule } from './hero.module'; | ||
|
||
// #docregion router-config | ||
import { HashLocationStrategy, LocationStrategy } from '@angular/common'; | ||
import { RouterModule, UrlHandlingStrategy, UrlTree } from '@angular/router'; | ||
import { AppComponent } from './app.component'; | ||
|
||
class HybridUrlHandlingStrategy implements UrlHandlingStrategy { | ||
// use only process the `/hero` url | ||
shouldProcessUrl(url: UrlTree) { return url.toString().startsWith('/hero'); } | ||
extract(url: UrlTree) { return url; } | ||
merge(url: UrlTree, whole: UrlTree) { return url; } | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
UpgradeModule, | ||
HeroModule, | ||
RouterModule.forRoot([]) | ||
], | ||
providers: [ | ||
// use hash location strategy | ||
{ provide: LocationStrategy, useClass: HashLocationStrategy }, | ||
// use custom url handling strategy | ||
{ provide: UrlHandlingStrategy, useClass: HybridUrlHandlingStrategy } | ||
], | ||
declarations: [ AppComponent ], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule { } | ||
// #enddocregion router-config | ||
|
||
import { Villain } from '../villain'; | ||
|
||
export const villainDetail = { | ||
template: ` | ||
<h1>Villain detail</h1> | ||
<h2>{{$ctrl.villain.name}} - {{$ctrl.villain.description}}</h2> | ||
`, | ||
controller: function() { | ||
this.villain = new Villain(1, 'Mr. Nice', 'No More Mr. Nice Guy'); | ||
} | ||
}; | ||
|
||
angular.module('heroApp', ['ngRoute']) | ||
.component('villainDetail', villainDetail) | ||
.config(['$locationProvider', '$routeProvider', | ||
function config($locationProvider: angular.ILocationProvider, | ||
$routeProvider: angular.route.IRouteProvider) { | ||
// #docregion ajs-route | ||
$routeProvider | ||
.when('/villain', { template: '<villain-detail></villain-detail>' }); | ||
// #enddocregion ajs-route | ||
} | ||
]); |
32 changes: 32 additions & 0 deletions
32
public/docs/_examples/upgrade-module/ts/src/app/divide-routes/hero.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// #docregion | ||
import { Component } from '@angular/core'; | ||
import { Hero } from '../hero'; | ||
|
||
@Component({ | ||
template: ` | ||
<h1>Hero detail</h1> | ||
<h2>{{hero.name}} - {{hero.description}}</h2> | ||
` | ||
}) | ||
export class HeroDetailComponent { | ||
hero = new Hero(1, 'Windstorm', 'Specific powers of controlling winds'); | ||
} | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
// #docregion a-route | ||
RouterModule.forChild([ | ||
{ path: 'hero', children: [ | ||
{ path: '', component: HeroDetailComponent }, | ||
] }, | ||
]) | ||
// #enddocregion a-route | ||
], | ||
declarations: [ HeroDetailComponent ] | ||
}) | ||
export class HeroModule {} |
10 changes: 10 additions & 0 deletions
10
public/docs/_examples/upgrade-module/ts/src/app/divide-routes/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// #docregion | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { UpgradeModule } from '@angular/upgrade/static'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => { | ||
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule; | ||
upgrade.bootstrap(document.body, ['heroApp'], {strictDi: true}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class Villain { | ||
constructor(public id: number, | ||
public name: string, | ||
public description?: string) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
public/docs/_examples/upgrade-module/ts/src/index-divide-routes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Angular 2 Upgrade</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="styles.css"> | ||
|
||
<script src="https://code.angularjs.org/1.5.5/angular.js"></script> | ||
<script src="https://code.angularjs.org/1.5.5/angular-route.js"></script> | ||
|
||
<!-- Polyfills for older browsers --> | ||
<script src="node_modules/core-js/client/shim.min.js"></script> | ||
|
||
<script src="node_modules/zone.js/dist/zone.js"></script> | ||
<script src="node_modules/reflect-metadata/Reflect.js"></script> | ||
<script src="node_modules/systemjs/dist/system.src.js"></script> | ||
|
||
<script src="systemjs.config.1.js"></script> | ||
<script> | ||
System.import('app/divide-routes/main') | ||
.then(null, console.error.bind(console)); | ||
</script> | ||
</head> | ||
|
||
<!--#docregion body--> | ||
<body> | ||
<my-app>Loading...</my-app> | ||
</body> | ||
<!--#enddocregion body--> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
public/docs/_examples/upgrade-module/ts/src/systemjs.config.1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* System configuration for Angular samples | ||
* Adjust as necessary for your application needs. | ||
*/ | ||
(function (global) { | ||
System.config({ | ||
paths: { | ||
// paths serve as alias | ||
'npm:': 'node_modules/' | ||
}, | ||
// map tells the System loader where to look for things | ||
map: { | ||
// our app is within the app folder | ||
app: 'app', | ||
// angular bundles | ||
'@angular/core': 'npm:@angular/core/bundles/core.umd.js', | ||
'@angular/common': 'npm:@angular/common/bundles/common.umd.js', | ||
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', | ||
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', | ||
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', | ||
'@angular/http': 'npm:@angular/http/bundles/http.umd.js', | ||
'@angular/router': 'npm:@angular/router/bundles/router.umd.js', | ||
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', | ||
// #docregion upgrade-static-umd | ||
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js', | ||
// #enddocregion upgrade-static-umd | ||
|
||
// other libraries | ||
'rxjs': 'npm:rxjs', | ||
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js' | ||
}, | ||
// packages tells the System loader how to load when no filename and/or no extension | ||
packages: { | ||
app: { | ||
main: './main.js', | ||
defaultExtension: 'js' | ||
}, | ||
rxjs: { | ||
defaultExtension: 'js' | ||
} | ||
} | ||
}); | ||
})(this); |
Oops, something went wrong.