2016-09-15 70 views
1

我试图设立Angular2和SystemJs,例如从外部库,这是像这样定义的,我可以导入组件构建环境:力打字稿承认__moduleName

@Component({ 
    moduleId: __moduleName, 
    selector: 'foo-selector', 
    templateUrl: 'foo.component.html' 
}) 

我知道肯定这是我想要使用的,因为它在我运行它时起作用。但是Typescript编译失败,因为它无法识别moduleName。我怎么能告诉Typescript认识到这一点,或者至少不要抱怨呢?

这是打字稿版本2.1.0-dev.20160915和moduletsconfig.json

回答

2

您可以尝试这一行添加到您的typings/index.d.ts文件设置为system

declare var __moduleName: string; 
+0

我有同样的问题......但在我的情况下,没有编译错误..但在浏览器中我得到'localhost /:23错误:(SystemJS)__moduleName未定义'...有没有解决方案? – Guna

+0

你的tsconfig.json是什么样的?具体地说'compilerOptions.module'部 – yurzui

+0

是啊..像这样, “compilerOptions”:{ “目标”: “ES5”, “模块”: “AMD”, “moduleResolution”: “节点”} – Guna