Javascript 将AMD模块导入Angular 2 TypeScript模块

Javascript 将AMD模块导入Angular 2 TypeScript模块,javascript,typescript,angular,amd,Javascript,Typescript,Angular,Amd,我在“test.js”文件中定义了以下AMD模块: 然后我使用System.JS加载这个模块,模块加载没有任何问题 我的问题是如何在Angular 2 TypeScript模块定义中包含该模块 import myModule = require('myModule'); 上述操作将不起作用,因为它会抱怨找不到“myModule” 我需要能够访问“链接”功能从我的AMD模块内我的Angular 2模块 有什么想法吗?以下是关于如何将现有AMD遗留模块与Angular 2结合使用的说明 [

我在“test.js”文件中定义了以下AMD模块:

然后我使用System.JS加载这个模块,模块加载没有任何问题

我的问题是如何在Angular 2 TypeScript模块定义中包含该模块

import myModule = require('myModule');    
上述操作将不起作用,因为它会抱怨找不到“myModule”

我需要能够访问“链接”功能从我的AMD模块内我的Angular 2模块

有什么想法吗?

以下是关于如何将现有AMD遗留模块与Angular 2结合使用的说明

[注意:为了演示,我对您的函数做了一些更改]

AMD mod-

define(
  'myModule',
  function() {
    'use strict';

    return function(module) {
        return {
          restrict: 'A',
          link: link
        };

        function link(scope, element, attrs) {
          console.log("Link function called");
        }
    };
  });
这是系统Js配置-

System.config({
  //use typescript for compilation
  transpiler: 'typescript',
  //typescript compiler options
  typescriptOptions: {
    emitDecoratorMetadata: true
  },
  //map tells the System loader where to look for things
  map: {
    app: "./src",
    myModule: './myModule.js'
  },
  //packages defines our app package
  packages: {
    app: {
      main: './main.ts',
      defaultExtension: 'ts'
    },
    legacy: {
      defaultExtension: 'js',
    }
  }
});

为什么不使用ngForward将angular1.x模块升级/迁移到“angular2”呢?我无法升级该模块,因为它是“属性指令”。我们不想创建一个新的Angular 2组件,而是想通过将AMD模块导入到TypeScript中,重新使用版本1中已经存在的相同代码。我正在尝试演示plunker,但它似乎不是working@henry74-为我工作。你能告诉我错误是什么吗?我是否遗漏了什么,或者点击每个名字对应的按钮“Brad[Say Hello]”应该会更改Hello Angular2标题…因为点击任何按钮似乎对我没有任何帮助。问题是如何导入遗留AMD模块。它与单击无关。如您所见,在app.ts中,我们将AMD模块函数称为-console.log(myModule().link());
System.config({
  //use typescript for compilation
  transpiler: 'typescript',
  //typescript compiler options
  typescriptOptions: {
    emitDecoratorMetadata: true
  },
  //map tells the System loader where to look for things
  map: {
    app: "./src",
    myModule: './myModule.js'
  },
  //packages defines our app package
  packages: {
    app: {
      main: './main.ts',
      defaultExtension: 'ts'
    },
    legacy: {
      defaultExtension: 'js',
    }
  }
});