Skip to content

Commit 901300a

Browse files
authored
feat(Angular 5.0): update engine-etc for angular 5.0 & Domino (#437)
* feat(5.0): update engine-etc for angular 5.0-rc1 WIP - More updates to come * remove ng 4 references * update source maps for faster HMR builds * use aspnetcore-engine & misc updates and fixes * update to 5.0 official Closes #434 Closes #435 Closes #430 Closes #424
1 parent 5e32bf1 commit 901300a

34 files changed

+153
-679
lines changed

ClientApp/app/app.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="col-sm-3">
2-
<nav-menu></nav-menu>
2+
<app-nav-menu></app-nav-menu>
33
</div>
44
<div class="col-sm-9 body-content">
55
<router-outlet></router-outlet>

ClientApp/app/app.component.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnDestroy, Inject, ViewEncapsulation, RendererFactory2, PLATFORM_ID } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, Inject, ViewEncapsulation, RendererFactory2, PLATFORM_ID, Injector } from '@angular/core';
22
import { Router, NavigationEnd, ActivatedRoute, PRIMARY_OUTLET } from '@angular/router';
33
import { Meta, Title, DOCUMENT, MetaDefinition } from '@angular/platform-browser';
44
import { Subscription } from 'rxjs/Subscription';
@@ -7,10 +7,10 @@ import { LinkService } from './shared/link.service';
77

88
// i18n support
99
import { TranslateService } from '@ngx-translate/core';
10-
import { REQUEST } from './shared/constants/request';
10+
import { REQUEST } from '@nguniversal/aspnetcore-engine';
1111

1212
@Component({
13-
selector: 'app',
13+
selector: 'app-root',
1414
templateUrl: './app.component.html',
1515
styleUrls: ['./app.component.scss'],
1616
encapsulation: ViewEncapsulation.None
@@ -23,6 +23,7 @@ export class AppComponent implements OnInit, OnDestroy {
2323
private defaultPageTitle: string = 'My App';
2424

2525
private routerSub$: Subscription;
26+
private request;
2627

2728
constructor(
2829
private router: Router,
@@ -31,14 +32,16 @@ export class AppComponent implements OnInit, OnDestroy {
3132
private meta: Meta,
3233
private linkService: LinkService,
3334
public translate: TranslateService,
34-
@Inject(REQUEST) private request
35+
private injector: Injector
3536
) {
3637
// this language will be used as a fallback when a translation isn't found in the current language
3738
translate.setDefaultLang('en');
3839

3940
// the lang to use, if the lang isn't available, it will use the current loader to get them
4041
translate.use('en');
4142

43+
this.request = this.injector.get(REQUEST);
44+
4245
console.log(`What's our REQUEST Object look like?`);
4346
console.log(`The Request object only really exists on the Server, but on the Browser we can at least see Cookies`);
4447
console.log(this.request);

ClientApp/app/app.module.browser.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { BrowserModule } from '@angular/platform-browser';
33
import { APP_BASE_HREF } from '@angular/common';
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
55

6-
import { ORIGIN_URL } from './shared/constants/baseurl.constants';
6+
import { ORIGIN_URL, REQUEST } from '@nguniversal/aspnetcore-engine';
77
import { AppModuleShared } from './app.module';
88
import { AppComponent } from './app.component';
9-
import { REQUEST } from './shared/constants/request';
10-
import { BrowserTransferStateModule } from '../modules/transfer-state/browser-transfer-state.module';
11-
9+
import { BrowserTransferStateModule } from '@angular/platform-browser';
1210
import { BrowserPrebootModule } from 'preboot/browser';
1311

1412
export function getOriginUrl() {
@@ -23,12 +21,8 @@ export function getRequest() {
2321
@NgModule({
2422
bootstrap: [AppComponent],
2523
imports: [
26-
BrowserModule.withServerTransition({
27-
appId: 'my-app-id' // make sure this matches with your Server NgModule
28-
}),
2924
BrowserPrebootModule.replayEvents(),
3025
BrowserAnimationsModule,
31-
BrowserTransferStateModule,
3226

3327
// Our Common AppModule
3428
AppModuleShared

ClientApp/app/app.module.server.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,28 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55

66
import { AppModuleShared } from './app.module';
77
import { AppComponent } from './app.component';
8-
import { ServerTransferStateModule } from '../modules/transfer-state/server-transfer-state.module';
9-
import { TransferState } from '../modules/transfer-state/transfer-state';
8+
import { ServerTransferStateModule } from '@angular/platform-server';
109

1110
import { ServerPrebootModule } from 'preboot/server';
1211

1312
@NgModule({
1413
bootstrap: [AppComponent],
1514
imports: [
16-
BrowserModule.withServerTransition({
17-
appId: 'my-app-id' // make sure this matches with your Browser NgModule
18-
}),
15+
// Our Common AppModule
16+
AppModuleShared,
17+
1918
ServerModule,
20-
ServerPrebootModule.recordEvents({ appRoot: 'app' }),
19+
ServerPrebootModule.recordEvents({ appRoot: 'app-root' }),
2120
NoopAnimationsModule,
2221

23-
ServerTransferStateModule,
24-
25-
// Our Common AppModule
26-
AppModuleShared
22+
// HttpTransferCacheModule still needs fixes for 5.0
23+
// Leave this commented out for now, as it breaks Server-renders
24+
// Looking into fixes for this! - @MarkPieszak
25+
// ServerTransferStateModule // <-- broken for the time-being with ASP.NET
2726
]
2827
})
2928
export class AppModule {
3029

31-
constructor(private transferState: TransferState) { }
30+
constructor() { }
3231

33-
// Gotcha (needs to be an arrow function)
34-
ngOnBootstrap = () => {
35-
this.transferState.inject();
36-
}
3732
}

ClientApp/app/app.module.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { NgModule, Inject } from '@angular/core';
22
import { RouterModule, PreloadAllModules } from '@angular/router';
33
import { CommonModule, APP_BASE_HREF } from '@angular/common';
44
import { HttpModule, Http } from '@angular/http';
5+
import { HttpClientModule, HttpClient } from '@angular/common/http';
56
import { FormsModule } from '@angular/forms';
7+
import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser';
8+
import { TransferHttpCacheModule } from '@nguniversal/common';
69

710
import { Ng2BootstrapModule } from 'ngx-bootstrap';
811

@@ -16,17 +19,14 @@ import { HomeComponent } from './containers/home/home.component';
1619
import { UsersComponent } from './containers/users/users.component';
1720
import { UserDetailComponent } from './components/user-detail/user-detail.component';
1821
import { CounterComponent } from './containers/counter/counter.component';
19-
// import { ChatComponent } from './containers/chat/chat.component';
2022
import { NotFoundComponent } from './containers/not-found/not-found.component';
2123
import { NgxBootstrapComponent } from './containers/ngx-bootstrap-demo/ngx-bootstrap.component';
2224

2325
import { LinkService } from './shared/link.service';
2426
import { UserService } from './shared/user.service';
25-
// import { ConnectionResolver } from './shared/route.resolver';
26-
import { ORIGIN_URL } from './shared/constants/baseurl.constants';
27-
import { TransferHttpModule } from '../modules/transfer-http/transfer-http.module';
27+
import { ORIGIN_URL } from '@nguniversal/aspnetcore-engine';
2828

29-
export function createTranslateLoader(http: Http, baseHref) {
29+
export function createTranslateLoader(http: HttpClient, baseHref) {
3030
// Temporary Azure hack
3131
if (baseHref === null && typeof window !== 'undefined') {
3232
baseHref = window.location.origin;
@@ -43,24 +43,28 @@ export function createTranslateLoader(http: Http, baseHref) {
4343
UsersComponent,
4444
UserDetailComponent,
4545
HomeComponent,
46-
// ChatComponent,
4746
NotFoundComponent,
4847
NgxBootstrapComponent
4948
],
5049
imports: [
5150
CommonModule,
52-
HttpModule,
51+
BrowserModule.withServerTransition({
52+
appId: 'my-app-id' // make sure this matches with your Server NgModule
53+
}),
54+
HttpClientModule,
55+
TransferHttpCacheModule,
56+
BrowserTransferStateModule,
57+
58+
5359
FormsModule,
5460
Ng2BootstrapModule.forRoot(), // You could also split this up if you don't want the Entire Module imported
5561

56-
TransferHttpModule, // Our Http TransferData method
57-
5862
// i18n support
5963
TranslateModule.forRoot({
6064
loader: {
6165
provide: TranslateLoader,
6266
useFactory: (createTranslateLoader),
63-
deps: [Http, [ORIGIN_URL]]
67+
deps: [HttpClient, [ORIGIN_URL]]
6468
}
6569
}),
6670

@@ -145,9 +149,9 @@ export function createTranslateLoader(http: Http, baseHref) {
145149
providers: [
146150
LinkService,
147151
UserService,
148-
// ConnectionResolver,
149152
TranslateModule
150-
]
153+
],
154+
bootstrap: [AppComponent]
151155
})
152156
export class AppModuleShared {
153157
}

ClientApp/app/components/navmenu/navmenu.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<span class='icon-bar'></span>
99
<span class='icon-bar'></span>
1010
</button>
11-
<a [routerLink]="['/home']" class='navbar-link'>Angular 4 Universal & ASP.NET Core</a>
11+
<a [routerLink]="['/home']" class='navbar-link'>Angular 5 Universal & ASP.NET Core</a>
1212
</div>
1313
</div>
1414
<div class='clearfix'></div>
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Component } from '@angular/core';
22

33
@Component({
4-
selector: 'nav-menu',
4+
selector: 'app-nav-menu',
55
templateUrl: './navmenu.component.html',
66
styleUrls: ['./navmenu.component.css']
77
})
88

99
export class NavMenuComponent {
10-
collapse: string = "collapse";
10+
collapse: string = 'collapse';
1111

1212
collapseNavbar(): void {
1313
if (this.collapse.length > 1) {
14-
this.collapse = "";
14+
this.collapse = '';
1515
} else {
16-
this.collapse = "collapse";
16+
this.collapse = 'collapse';
1717
}
1818
}
1919

2020
collapseMenu() {
21-
this.collapse = "collapse"
21+
this.collapse = 'collapse';
2222
}
2323
}

ClientApp/app/components/user-detail/user-detail.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IUser } from '../../models/User';
33
import { UserService } from '../../shared/user.service';
44

55
@Component({
6-
selector: 'user-detail',
6+
selector: 'app-user-detail',
77
templateUrl: './user-detail.component.html'
88
})
99
export class UserDetailComponent {

ClientApp/app/containers/counter/counter.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from '@angular/core';
22

33
@Component({
4-
selector: 'counter',
4+
selector: 'app-counter',
55
templateUrl: './counter.component.html'
66
})
77
export class CounterComponent {

ClientApp/app/containers/home/home.component.html

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1>{{ title }}</h1>
22

33
<blockquote>
4-
<strong>Enjoy the latest features from .NET Core & Angular 4.0!</strong>
4+
<strong>Enjoy the latest features from .NET Core & Angular 5.0!</strong>
55
<br> For more info check the repo here: <a href="https://github.com/MarkPieszak/aspnetcore-angular2-universal">AspNetCore-Angular2-Universal repo</a>
66
<br><br>
77
</blockquote>
@@ -12,7 +12,7 @@ <h2>{{ 'HOME_FEATURE_LIST_TITLE' | translate }} </h2>
1212
<ul>
1313
<li>ASP.NET Core 2.0 :: ( Visual Studio 2017 )</li>
1414
<li>
15-
Angular 4.* front-end UI framework
15+
Angular 5.* front-end UI framework
1616
<ul>
1717
<li>Angular **platform-server** (aka: Universal) - server-side rendering for SEO, deep-linking, and
1818
incredible performance.</li>
@@ -22,25 +22,17 @@ <h2>{{ 'HOME_FEATURE_LIST_TITLE' | translate }} </h2>
2222
</li>
2323
<li>
2424
The latest TypeScript 2.* features
25-
<!--<ul>
26-
<li>
27-
"Path" support example - create your own custom directory paths to avoid `../../` directory diving.<br />
28-
Check the <a href="https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/tsconfig.json">tsconfig</a> to see how they are setup.
29-
</li>
30-
</ul>-->
3125
</li>
3226
<li>
3327
Webpack
3428
<ul>
35-
<!--<li>TS2 aware path support</li>-->
3629
<li>Hot Module Reloading/Replacement for an amazing development experience.</li>
3730
<li>Tree-shaking</li>
3831
</ul>
3932
</li>
4033

4134
<li>Bootstrap (ngx-bootstrap) : Bootstrap capable of being rendered even on the server.</li>
4235
<li>Unit testing via karma & jasmine.</li>
43-
<!--<li>e2e testing via protractor.</li>-->
4436
</ul>
4537

4638
</div>

ClientApp/app/containers/home/home.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TranslateService } from '@ngx-translate/core';
88
})
99
export class HomeComponent implements OnInit {
1010

11-
title: string = 'Angular 4.0 Universal & ASP.NET Core 2.0 advanced starter-kit';
11+
title: string = 'Angular 5.x Universal & ASP.NET Core 2.0 advanced starter-kit';
1212

1313
// Use "constructor"s only for dependency injection
1414
constructor(

ClientApp/app/containers/lazy/lazy.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from '@angular/core';
22

33
@Component({
4-
selector: 'lazy-view',
4+
selector: 'app-lazy-view',
55
template: `
66
<h1>Lazy-Loaded Component!</h1>
77
<blockquote>

ClientApp/app/containers/not-found/not-found.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22

33
@Component({
4-
selector: 'not-found',
4+
selector: 'app-not-found',
55
templateUrl: './not-found.component.html'
66
})
77
export class NotFoundComponent implements OnInit {

ClientApp/app/containers/users/users.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ <h2>Users</h2>
2626
</button>
2727
</li>
2828
</ul>
29-
<user-detail [user]="selectedUser"></user-detail>
29+
<app-user-detail [user]="selectedUser"></app-user-detail>

ClientApp/app/containers/users/users.component.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IUser } from '../../models/User';
77
import { UserService } from '../../shared/user.service';
88

99
@Component({
10-
selector: 'users',
10+
selector: 'app-users',
1111
templateUrl: './users.component.html',
1212
styleUrls: ['./users.component.css'],
1313
animations: [
@@ -31,15 +31,16 @@ export class UsersComponent implements OnInit {
3131
selectedUser: IUser;
3232

3333
// Use "constructor"s only for dependency injection
34-
constructor(private userService: UserService) { }
34+
constructor(
35+
private userService: UserService
36+
) { }
3537

3638
// Here you want to handle anything with @Input()'s @Output()'s
3739
// Data retrieval / etc - this is when the Component is "ready" and wired up
3840
ngOnInit() {
3941
this.userService.getUsers().subscribe(result => {
40-
console.log('Get user result: ', result);
41-
console.log('TransferHttp [GET] /api/users/allresult', result);
42-
this.users = result as IUser[];
42+
console.log('HttpClient [GET] /api/users/allresult', result);
43+
this.users = result;
4344
});
4445
}
4546

@@ -50,10 +51,8 @@ export class UsersComponent implements OnInit {
5051
deleteUser(user) {
5152
this.userService.deleteUser(user).subscribe(result => {
5253
console.log('Delete user result: ', result);
53-
if (result.ok) {
54-
let position = this.users.indexOf(user);
55-
this.users.splice(position, 1);
56-
}
54+
let position = this.users.indexOf(user);
55+
this.users.splice(position, 1);
5756
}, error => {
5857
console.log(`There was an issue. ${error._body}.`);
5958
});
@@ -62,9 +61,7 @@ export class UsersComponent implements OnInit {
6261
addUser(newUserName) {
6362
this.userService.addUser(newUserName).subscribe(result => {
6463
console.log('Post user result: ', result);
65-
if (result.ok) {
66-
this.users.push(result.json());
67-
}
64+
this.users.push(result);
6865
}, error => {
6966
console.log(`There was an issue. ${error._body}.`);
7067
});

ClientApp/app/shared/constants/baseurl.constants.ts

-3
This file was deleted.

ClientApp/app/shared/constants/request.ts

-3
This file was deleted.

0 commit comments

Comments
 (0)