mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +00:00
Update Angular2Spa to current versions of Angular 2, angular2-universal-preview, etc.
This commit is contained in:
@@ -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 };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user