1
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.27/system.src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/angular2-polyfills.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/Rx.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/angular2.dev.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/upgrade.dev.js"></script>
<body>
<h1>Angular 1 to 2</h1>
<script>
    angular.element(document).ready(function () {
        var upgrade_1 = require('angular2/upgrade');
        var upgradeAdapter = new upgrade_1.UpgradeAdapter();
        upgradeAdapter.bootstrap(document.body, ['app'], { strictDi: true });
    });
</script>
</body>
</html>

以上是我试图用来为 angular2 设置升级适配器的 html。

我目前只是试图加载升级适配器。script 标签中的上述代码是示例 typescript 代码根据 Angular 网站遵从 js 的内容。https://angular.io/docs/ts/latest/guide/upgrade.html#!#bootstrapping-hybrid-angular-1-2-applications

问题是我不断收到以下错误:“'require'未定义”。

为什么systemjs没有加载它?

4

1 回答 1

1

以下是有关如何设置升级适配器的详细步骤

https://medium.com/@SevenLee/configuration-tips-to-build-hybrid-angular-1-and-angular-2-project-in-real-world-230b715629dc#.g0tsratdm

我的主要问题是在我的 tsconfig 文件中,我需要使用 "module": "system" 而不是 "module": "commonjs"

然后将升级适配器代码编译为:

system.register(['angular2/upgrade'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var upgrade_1;
var upgradeAdapter;
return {
    setters:[
        function (upgrade_1_1) {
            upgrade_1 = upgrade_1_1;
        }],
    execute: function() {
        upgradeAdapter = new upgrade_1.UpgradeAdapter();
        upgradeAdapter.bootstrap(document.body, ['app'], { strictDi: true });
    }
}
});
于 2016-05-17T08:12:17.947 回答