简体   繁体   English

如何使用typescript让angular2在eclipse中工作

[英]How to get angular2 to work in eclipse with typescript

So I was starting researching about angular2 and since I saw so many references to typescript being prefered I am trying to switch to it from javascript. 所以我开始研究angular2,因为我看到很多关于打字稿的引用,我试图从javascript切换到它。 Problem is, I saw a nice little guide I could follow to install it all in eclipse (angular, javascript, everything needed to launch the 5 minute guide code on the main page of angular), so I did it and managed to get it to work. 问题是,我看到了一个很好的小指南我可以按照eclipse安装它(角度,javascript,在角度主页上启动5分钟指南代码所需的一切),所以我做了它并设法得到它工作。

Now I would like to do the same with typescript, but I find myself lost since it doesn't seem to be working, I can't launch code, it's like node.js isn't working anymore, but since I do not know what the expected result is, I am not sure what is missing. 现在我想对打字稿做同样的事情,但我发现自己失去了因为它似乎没有工作,我无法启动代码,就像node.js不再工作,但因为我不知道预期的结果是什么,我不确定缺少什么。

For example, I re did the 5 minute guide and notice as a difference that I do not have the installation of the modules, nor any run-as configuration ready, in fact, I can't manage to run as any typescript code I try to do. 例如,我做了5分钟的指导,并注意到我没有安装模块,也没有准备好任何运行配置,事实上,我无法设法运行任何打字机代码我尝试去做。

What I did was: 我做的是:

1- Install Eclipse Mars, other guys uses older versions 1-安装Eclipse Mars,其他人使用旧版本

2- Install Node.js 2-安装Node.js.

3- Install WildFly Server 3-安装WildFly Server

4- Install TypeScript plugin https://marketplace.eclipse.org/content/typescript 4-安装TypeScript插件https://marketplace.eclipse.org/content/typescript

5- Import my project in eclipse, you may have to create a new static web project and add your files in there. 5-在eclipse中导入我的项目,你可能需要创建一个新的静态web项目并在那里添加你的文件。 The 5 minute quick start is not an eclipse web project so you may not be able to import this. 5分钟快速启动不是eclipse Web项目,因此您可能无法导入它。 Do not forget to copy and past the same structure with the node modules that you have 不要忘记使用您拥有的节点模块复制和通过相同的结构

6- Right click on the project > Configure > Enable Typescript Builder 6-右键单击项目>配置>启用Typescript Builder

7- Right Click the project > Properties > TypeScript > Compiler and configure as follows: 7-右键单击项目>属性> TypeScript>编译器,并配置如下:

在此输入图像描述

I hope this will do it for you. 我希望这会为你做到。

Remember, this plugin does not respect json configuration file, so you have to do this manually as in the screenshot. 请记住,此插件不尊重json配置文件,因此您必须手动执行此操作,如屏幕截图所示。 Also, if you are going to provide arguments to your component constructor, You will have errors. 此外,如果要为组件构造函数提供参数,则会出现错误。 Let me know if you got those. 如果你有这些,请告诉我。 Another thing to mention is that using some annotations like @Input will not work, you will have to use inputs:[] inside your @Component annotation. 另外要提到的是,使用像@Input这样的注释是行不通的,你必须在@Component注释中使用输入:[]。

You can try to add those plugins on top of Mars: 你可以尝试在火星上添加这些插件:

Those 2 are incubating but already provide good features. 这两个正在孵化,但已经提供了良好的功能。 There is another one, that I didn't try but which has some popularity: 还有一个,我没有尝试,但有一些受欢迎程度:

Eclipse >= Neon Eclipse> = Neon

Eclipse Oxygen Eclipse氧气

Default javascript installation, then added the default free plugin for angular 2 / typescript from here: 默认的javascript安装,然后从这里添加angular 2 / typescript的默认免费插件:

angular2.ide - http://oss.opensagres.fr/angular2-eclipse/1.3.0/ angular2.ide - http://oss.opensagres.fr/angular2-eclipse/1.3.0/

After installing I opened an existing Angular 4 / TS project, worked fine. 安装完成后,我打开了现有的Angular 4 / TS项目,工作正常。 I then installed support for .scss from http://www.liclipse.com/text/updates . 然后我从http://www.liclipse.com/text/updates安装了对.scss的支持。 All setup and configured with Typescript 2.4.1 / nodejs v6.9.4. 全部设置并使用Typescript 2.4.1 / nodejs v6.9.4进行配置。

But within days it now fails to open .ts files at all. 但是几天之内它根本无法打开.ts文件。 Re-installation of the ng plugin did not fix it, I uninstalled liclipse plugin and no change either. 重新安装ng插件没有解决它,我卸载了liclipse插件,也没有改变。 It basically leaves eclipse unusable for ng4 projects as is. 它基本上使eclipse无法用于ng4项目。

The logs show the following errors. 日志显示以下错误。

org.eclipse.core.runtime.CoreException: Plug-in "ts.eclipse.ide.jsdt.ui" was unable to instantiate class "ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptEditor".
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:188)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
...
Caused by: java.lang.NoClassDefFoundError: org/eclipse/wst/jsdt/ui/text/JavaScriptSourceViewerConfiguration
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
...
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.wst.jsdt.ui (441).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:112)
    at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
 ...
 Caused by: java.lang.ClassFormatError: Name index 1 in LocalVariableTable has bad constant type in class file org/eclipse/wst/jsdt/internal/core/JavaModelManager

I found TypeEcs plugin for Typescript 我找到了TypeEcs插件

it provide below. 它在下面提供。

•Syntax highlighting •语法突出显示

•Code Completion •代码完成

•Code Outline •代码大纲

•Find References •查找参考文献

•Rename / Refactor •重命名/重构

•Open Type •打开类型

•Code Compilation •代码编译

•Format Code •格式代码

•Comment Code •评论代码

•Open Declaration •公开宣言

•Mark Occurences •Mark Occurences

•Type Script Debug •键入脚本调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM