无法在Visual Code中的角度1组件内运行Angular 2 Component

时间:2017-01-18 12:18:01

标签: angularjs angular debugging interop hybrid

我的 Index.html

<!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>
定义Angular 1模块的

App.js

angular.module('ng1_module',[]);
加载angular2的

System.js

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' },
}
});

最后 Main.ts 执行角度1和角度2模块的自举

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']);

});

我在控制台中收到3个错误,我无法解决。

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}

让我知道我哪里出错了。只是概述我有一个在Production上运行的Angular 1应用程序,我只是想开始使用Angular 2组件。提前感谢任何形式的帮助。

添加我的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"
}
}

0 个答案:

没有答案