'Can't run an Angular 2 Component inside an Angular 1 component in Visual Code
My Index.html is
<!doctype html>
<html>
<head></head>
<body>
<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.js"></script>
<script type="text/javascript" src="app/app.js"></script>
<script>
angular.bootstrap(document, ['ng1_module']);
System.import('main');
</script>
<my-app></my-app>
</body>
</html>
App.js which defines the Angular 1 Module is
angular.module('ng1_module',[]);
System.js which loads the angular2 is
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',
'main': 'app/main.js',
// 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',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// 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: 'app/main.js', defaultExtension: 'js' },
'api': { defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
}
});
Finally Main.ts that does the bootstrapping of both Angular 1 as well as Angular 2 modules is
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, ['ng1_module']);
});
I am getting a 3 errors in console which I am unable to resolve:
http://localhost:something/node_modules/@angular/upgrade/bundles/upgrade.umd.js/static 404 (Not Found)
Unhandled Promise rejection: (SystemJS) XHR error (404 Not Found) loading http://localhost:something/node_modules/@angular/upgrade/bundles/upgrade.umd.js/static
ZoneAwareError {__zone_symbol__error: Error: Uncaught (in promise): Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:…, rejection: ZoneAwareError, promise: ZoneAwarePromise, zone: Zone, task: ZoneTask}
Where am I going wrong? Just an overview: I have a Angular 1 application running on Production and I am just trying to start using Angular 2 components.
Adding my package.json:
{
"name": "something",
"version": "0.0.1",
"description": "",
"private": "true",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w"
},
"dependencies": {
"@angular/common": "~2.2.1",
"@angular/compiler": "~2.2.1",
"@angular/compiler-cli": "~2.2.1",
"@angular/core": "~2.2.1",
"@angular/forms": "~2.2.1",
"@angular/http": "~2.2.1",
"@angular/platform-browser": "~2.2.1",
"@angular/platform-browser-dynamic": "~2.2.1",
"@angular/platform-server": "~2.2.1",
"@angular/router": "~3.2.1",
"@angular/upgrade": "~2.2.1",
"angular2-in-memory-web-api": "0.0.21",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"ie-shim": "^0.1.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.40",
"zone.js": "~0.6.26"
},
"devDependencies": {
"angular-jsdoc": "^0.3.8",
"angular-mocks": "^1.3.14",
"@types/node": "^6.0.48",
"angular2-router-loader": "^0.3.4",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "^2.2.4",
"css-loader": "^0.25.0",
"raw-loader": "^0.5.1",
"to-string-loader": "^1.1.4",
"typescript": "~2.0.10"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|