2016-01-13 71 views
0

我可能会在这里丢失一些明显的东西,但我怎么会导入一个不导出任何内容的第三方库。在angular2中导入第三方库

我尝试了所有的以下

import '../bower_components/asn1js/asn1'; 
import {ASN1} from '../bower_components/asn1js/asn1'; 
import ASN1 from '../bower_components/asn1js/asn1'; 

均未奏效。

如果你看看在asn1.js文件,你可以看到底如下:

// export globals 
if (typeof module !== 'undefined') { module.exports = ASN1; } else { window.ASN1 = ASN1; } 

这似乎是试图将自己出口。我不熟悉这个,所以你可以解释我:

  • 什么决定模块是否未定义?应该在哪里定义?
  • 如果它未定义或api不使用导出,我如何导入/使用它?
+0

[在angular2包装第三方组件]的可能的复制(http://stackoverflow.com/questions/36984382/wrapping-3rd-party-components-in-angular2) – John

回答

0

因为它是导出全局对象,所以不需要导入它。 如果有什么你会导入将是它的TypeScript.definition文件,但我不知道还有一个。

所以你应该试试以下。

@Component({ 
    selector: 'Component', 
    directives: [], 
    providers: [], 
    template: ` 
    <h3>Component</h3> 
    ` 
}) 
export class Componentimplements OnInit{  
    constructor(private _asn1 : window.ASN1 || ASN1){ 

    } 

    ngOnInit(){} 
}