From e8dd8089d46213f340e565670619b9c05e91d7b0 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Thu, 9 Feb 2017 15:14:30 +0000 Subject: [PATCH] In Angular2Spa, fix HMR with 2.4.6 and relax version dependency to allow arbitrary 2.x again. Fixes #643 --- templates/Angular2Spa/ClientApp/boot-client.ts | 9 ++++++++- templates/Angular2Spa/package-2.4.5.json | 16 ++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/templates/Angular2Spa/ClientApp/boot-client.ts b/templates/Angular2Spa/ClientApp/boot-client.ts index 03d73a7..963598a 100644 --- a/templates/Angular2Spa/ClientApp/boot-client.ts +++ b/templates/Angular2Spa/ClientApp/boot-client.ts @@ -3,11 +3,18 @@ import { enableProdMode } from '@angular/core'; import { platformUniversalDynamic } from 'angular2-universal'; import { AppModule } from './app/app.module'; import 'bootstrap'; +const rootElemTagName = 'app'; // Update this if you change your root component selector // Enable either Hot Module Reloading or production mode if (module['hot']) { module['hot'].accept(); - module['hot'].dispose(() => { platform.destroy(); }); + module['hot'].dispose(() => { + // Before restarting the app, we create a new root element and dispose the old one + const oldRootElem = document.querySelector(rootElemTagName); + const newRootElem = document.createElement(rootElemTagName); + oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem); + platform.destroy(); + }); } else { enableProdMode(); } diff --git a/templates/Angular2Spa/package-2.4.5.json b/templates/Angular2Spa/package-2.4.5.json index b33d3c6..213be5c 100644 --- a/templates/Angular2Spa/package-2.4.5.json +++ b/templates/Angular2Spa/package-2.4.5.json @@ -5,14 +5,14 @@ "test": "karma start ClientApp/test/karma.conf.js" }, "dependencies": { - "@angular/common": "2.4.5", - "@angular/compiler": "2.4.5", - "@angular/core": "2.4.5", - "@angular/forms": "2.4.5", - "@angular/http": "2.4.5", - "@angular/platform-browser": "2.4.5", - "@angular/platform-browser-dynamic": "2.4.5", - "@angular/platform-server": "2.4.5", + "@angular/common": "^2.4.5", + "@angular/compiler": "^2.4.5", + "@angular/core": "^2.4.5", + "@angular/forms": "^2.4.5", + "@angular/http": "^2.4.5", + "@angular/platform-browser": "^2.4.5", + "@angular/platform-browser-dynamic": "^2.4.5", + "@angular/platform-server": "^2.4.5", "@angular/router": "^3.4.5", "@types/node": "^6.0.42", "angular2-platform-node": "~2.0.11",