简体   繁体   English

Visual Studio 2015中的AngularJS Intellisense

[英]AngularJS Intellisense in Visual Studio 2015

Recently I started to use Visual Studio 2015 Community instead of Brackets. 最近,我开始使用Visual Studio 2015 Community而不是Brackets。 As it is said on a website, it has some kind of support of Angular, however, I did not even see it anywhere instead of HTML files. 就像在网站上所说的那样,它对Angular具有某种支持,但是,我什至没有看到它而不是HTML文件。 Even variable "angular", while hovering on it, prints 甚至将变量“ angular”悬停在其上时,也会打印

angular <type unknown>

I added an image to explain what I mean. 我添加了一张图片来解释我的意思。

在此处输入图片说明

I tried to change JavaScript TextEditor References to Implicit (Web), however, after reboot, it comes back to Implicit (Windows). 我试图将JavaScript TextEditor引用更改为Implicit(Web),但是,重新启动后,它又回到了Implicit(Windows)。

I use Web Essentials and I know that it has feature to create Intellisense JS and TS files, however, this features are always disabled. 我使用Web Essentials,并且知道它具有创建Intellisense JS和TS文件的功能,但是始终禁用此功能。 I opened each directory in my project and checked it, this feature was always turned off. 我打开了项目中的每个目录并进行了检查,此功能始终处于关闭状态。

In addition, I tried to create Scripts directory with _references.js manually, but it works very...baaad, I need to move it to another directory and return it into previous to make options like auto-sync available. 另外,我尝试使用_references.js手动创建Scripts目录,但是它的工作原理非常好... baaad,我需要将其移至另一个目录并将其返回到以前的目录,以使自动同步等选项可用。 The same thing is about _references.js 关于_references.js也是一样

To make this case more cleaner: I create _references.js manualy. 为了使这种情况更清晰:我手动创建_references.js。 Now it has its Anto-Sync and Update References options. 现在它具有Anto-Sync和Update References选项。 —> Reboot Visual Studio 2015 —> _references.js doesn't have such options anymore. —>重新启动Visual Studio 2015 —> _references.js不再具有此类选项。 However, even before reboot, if I update it, it will skip everything except app.js in root folder. 但是,即使在重新启动之前,如果我对其进行更新,它将跳过根文件夹中除app.js之外的所有内容。

PS AngularJS IntelliSense works in HTML files, ie I can place ng-* attributes. PS AngularJS IntelliSense可在HTML文件中运行,即可以放置ng- *属性。 So...I think, that something just doesn't work in VS 2015. PSS I use NodeJS for server-part of WebApp. 所以...我认为,有些事情在VS 2015中不起作用。PSS我将NodeJS用于WebApp的服务器部分。

Well, I understand you are looking for a solution to work with Instellisense and Visual Studio, no matter what. 好吧,我知道您正在寻找一种无论如何都可以与Instellisense和Visual Studio一起使用的解决方案。

I am using Visual Studio also, but I moved to work with TypeScript. 我也使用Visual Studio,但是我转而使用TypeScript。 It is actually writing a kind of extended strongly typed JavaScript. 它实际上是在编写一种扩展的强类型JavaScript。 That means you can declare the types of your variables. 这意味着您可以声明变量的类型。 Example: var x:string = 'test'; 示例: var x:string = 'test';

There are of courses advantages and disadvantages. 当然有优点和缺点。 I like the advantages, that's why I used it. 我喜欢这些优点,所以才使用它。

  1. You have to compile your code. 您必须编译您的代码。 Understand that as parsing your Javascript for error checking and a transformation process from *.ts files to become *.js files. 将其理解为解析Java代码以进行错误检查以及从*.ts文件到*.js文件的转换过程。
  2. You can add header files. 您可以添加文件。 Have you ever developed C/C++ apps? 您是否曾经开发过C / C ++应用程序? Well, in TypeScript you can add definition, or *.d files, which are in fact just header files for checking JavaScript function definitions. 好吧,在TypeScript中,您可以添加定义或*.d文件,它们实际上只是用于检查JavaScript函数定义的头文件。
  3. TypeScript on Visual Studio uses Intellisense. Visual Studio上的TypeScript使用Intellisense。 That's what we are talking about! 那就是我们在说的!

The #2 advantage is great. #2的优势很大。 It prevents you to execute wrong code like: 它可以防止您执行错误的代码,例如:

setTimeout(myFunc, 'abc');

This wouldn't work for the second param should be a number, and not string. 这对于第二个参数应该是数字而不是字符串不起作用。 But as I said, you have to add the definition files to your TypeScript solution in order to work ok. 但是正如我所说,您必须将定义文件添加到TypeScript解决方案中才能正常工作。

If you like trying that (you won't regret), follow these steps: 如果您想尝试一下(您不会后悔),请按照以下步骤操作:

  1. Download and Install TypeScript for Visual Studio - Follow the link https://www.typescriptlang.org/ 下载并安装适用于Visual Studio的TypeScript-单击链接https://www.typescriptlang.org/
  2. Create a TypeScript Projet - Very easy, there's a template already for that after installing the TypeScript for Visual Studio; 创建TypeScript Projet-很容易,在安装用于Visual Studio的TypeScript之后已经有一个模板。
  3. Add angular, jquery packages using NuGet 使用NuGet添加有角度的jquery包
  4. Install the following definition packages - angularjs.TypeScript.DefinitelyTyped - https://www.nuget.org/packages/angularjs.TypeScript.DefinitelyTyped/ 安装以下定义包 -angularjs.TypeScript.DefinitelyTyped- https ://www.nuget.org/packages/angularjs.TypeScript.DefinitelyTyped/

I believe this is an even better solution than just plain Intellisense, since it also prevents you from sending wrong parameters to functions in angular. 我相信这是一个比普通的Intellisense更好的解决方案,因为它还可以防止将错误的参数发送给angular函数。 Since JavaScript allows any variable to be of any type, it is really hard to do a code review when anything in your JS breaks. 由于JavaScript允许任何变量为任何类型,因此当JS中的任何内容中断时,实际上很难进行代码审查。 With TS, this shouldn't happen. 使用TS,这不应该发生。 If you do that, the compilation will fail. 如果这样做,编译将失败。

Have you tried using this at the beggining of your js file where you want Intellisense? 您是否曾在想要Intellisense的js文件的开头尝试过使用此功能?

/// <reference path="pathToAngular.js" />

https://msdn.microsoft.com/en-us/library/bb385682.aspx https://msdn.microsoft.com/zh-CN/library/bb385682.aspx

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

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