Update Angular2Spa to current versions of Angular 2, angular2-universal-preview, etc.

This commit is contained in:
SteveSandersonMS
2016-03-31 16:41:24 +01:00
parent 033a42ab42
commit 89c8dd3b36
8 changed files with 24 additions and 29 deletions

View File

@@ -1,22 +1,20 @@
import 'angular2-universal-preview/dist/server/universal-polyfill.js';
import 'angular2-universal-polyfills';
import * as ngCore from 'angular2/core';
import * as ngRouter from 'angular2/router';
import * as ngUniversal from 'angular2-universal-preview';
import { BASE_URL } from 'angular2-universal-preview/dist/server/src/http/node_http';
import * as ngUniversalRender from 'angular2-universal-preview/dist/server/src/render';
import { App } from './components/app/app';
export default function (params: any): Promise<{ html: string, globals?: any }> {
const serverBindings = [
ngRouter.ROUTER_BINDINGS,
ngUniversal.HTTP_PROVIDERS,
ngUniversal.SERVER_LOCATION_PROVIDERS,
ngUniversal.NODE_LOCATION_PROVIDERS,
ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
ngCore.provide(BASE_URL, { useValue: params.absoluteUrl }),
ngCore.provide(ngUniversal.BASE_URL, { useValue: params.absoluteUrl }),
ngCore.provide(ngUniversal.REQUEST_URL, { useValue: params.url })
];
return ngUniversalRender.renderToString(App, serverBindings).then(html => {
return ngUniversal.renderDocument('<app />', App, serverBindings).then(html => {
return { html };
});
}

View File

@@ -7,16 +7,14 @@ import { FetchData } from '../fetch-data/fetch-data';
import { Counter } from '../counter/counter';
@ng.Component({
selector: 'app'
selector: 'app',
template: require('./app.html'),
directives: [NavMenu, router.ROUTER_DIRECTIVES]
})
@router.RouteConfig([
{ path: '/', component: Home, name: 'Home' },
{ path: '/counter', component: Counter, name: 'Counter' },
{ path: '/fetch-data', component: FetchData, name: 'FetchData' }
])
@ng.View({
template: require('./app.html'),
directives: [NavMenu, router.ROUTER_DIRECTIVES]
})
export class App {
}

View File

@@ -1,9 +1,7 @@
import * as ng from 'angular2/core';
@ng.Component({
selector: 'counter'
})
@ng.View({
selector: 'counter',
template: require('./counter.html')
})
export class Counter {

View File

@@ -2,9 +2,7 @@ import * as ng from 'angular2/core';
import { Http } from 'angular2/http';
@ng.Component({
selector: 'fetch-data'
})
@ng.View({
selector: 'fetch-data',
template: require('./fetch-data.html')
})
export class FetchData {

View File

@@ -1,9 +1,7 @@
import * as ng from 'angular2/core';
@ng.Component({
selector: 'home'
})
@ng.View({
selector: 'home',
template: require('./home.html')
})
export class Home {

View File

@@ -2,9 +2,7 @@ import * as ng from 'angular2/core';
import * as router from 'angular2/router';
@ng.Component({
selector: 'nav-menu'
})
@ng.View({
selector: 'nav-menu',
template: require('./nav-menu.html'),
directives: [router.ROUTER_DIRECTIVES]
})

View File

@@ -18,18 +18,18 @@
"webpack-hot-middleware": "^2.10.0"
},
"dependencies": {
"angular2": "^2.0.0-beta.7",
"angular2-universal-preview": "^0.55.4",
"angular2": "2.0.0-beta.13",
"angular2-universal-preview": "^0.84.2",
"aspnet-prerendering": "^1.0.0",
"aspnet-webpack": "^1.0.1",
"css": "^2.2.1",
"es6-shim": "^0.33.13",
"es6-shim": "^0.35.0",
"isomorphic-fetch": "^2.2.1",
"parse5": "^1.5.1",
"preboot": "^1.1.3",
"reflect-metadata": "^0.1.2",
"rxjs": "^5.0.0-beta.2",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"webpack-externals-plugin": "^1.0.0",
"zone.js": "^0.5.15"
"zone.js": "^0.6.6"
}
}

View File

@@ -0,0 +1,7 @@
// This file is a workaround for angular2-universal-preview version 0.84.2 relying on the declaration of
// Node's 'url' module. Ideally it would not declare dependencies on Node APIs except where it also supplies
// the definitions itself.
declare module 'url' {
export interface Url {}
}