2016-05-30 66 views
1

我們有一個應用程序構建與需要js,jquery。現在我們想將角度2添加到應用程序中的其中一個屏幕上。我嘗試了幾個使用angular2的例子,它的功能非常好,工作正常。角2與實用js有要求js

現在我打算將它與我們的應用程序集成在一起。因此,按照下面的鏈接,我發現我們必須使用angular2 system.js而不是require.js https://github.com/angular/angular/issues/5412

但在這種情況下,我有一些實用JS其中,因爲它在不同的屏幕中使用我不能改變。該實用程序的JS在這種情況下,我將如何添加依賴我的新角2組件需要語法

define(['jquery','misc','utils','common','screenUtils'], 
    function(jQuery, misc,utils,common,screenUtils) { 
    //Public function goes here. 
return publicFunctions; 
} 
); 

請指點。我是angular2的新手,不知道如何用require來注入工具js。

import {Component} from '@angular/core'; 

@Component({ 
    selector: 'animate-app', 
    templateUrl: 'ts-src/animate.tpl.html', 
    host: {'class' : 'ng-animate page2Container'} 
}) 
export class AnimateComponent{ 
} 

請指教。

回答

0

我認爲你可以將你的JS文件配置到SystemJS中。加載器支持不同的模塊格式,如System,CommonJS和AMD。

這裏有一個例子:

System.config({ 
    map: { 
    yourlib: 'path-to/lib.js' 
    } 
}); 

然後你就那麼可以導入你的lib是這樣的:

import * as yourlib from 'yourlib'; 

import {test} as yourlib from 'yourlib'; 

看到這個plunkr作爲樣本(文件lib.js,config.js和src/app.js):https://plnkr.co/edit/nRaO0c4Qmr3KUcFhVHbq?p=preview