AngularJS intellisense not working on Visual Studio 2015

后端 未结 11 1362
粉色の甜心
粉色の甜心 2020-11-30 01:38

According to this post intellisense should also be working on the new VS 2015, but so far I only get intellisense for the angular object and not for the dependencies or my c

相关标签:
11条回答
  • 2020-11-30 02:23

    None of the above work for me. Mine is Visual Studio 2017 - Professional

    Yet I got it working using my solution here -->

    1. You have to reference the source by an enclosed /// <reference path="yourpath"/> even the source is in the same folder where you code is.
    2. Do NOT USE minified source. All your source has to be non-minified.
    3. If you store your path stmts in _reference.js file, make sure that file is at the same dir where your code file is.

    Although I can put the reference stmt inside my code file, I chose to use a separate file "_reference.js" to store it.

    You can put this with your code :

    /// <reference path="../_assets/JS-Main/angular-1.3.13.js" />
    
    var app = angular.module('app', ['ui.grid', 'ui.bootstrap']);
    app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
    

    Or you can enter this line into your _reference.js file

    /// <reference path="../_assets/JS-Main/angular-1.3.13.js" />
    

    After you have done all the above, you should be able to see the angular intellisense.

    You can do the same thing for others' intellisense like jQuery, Anytime, _underscore, etc... just keep adding path statements into the _reference.js file and you can also copy that _reference.js file to other websites if they have the same dir struct. Good luck!

    0 讨论(0)
  • 2020-11-30 02:24

    Follow this article to add more comprehensive intellisense to VS.

    http://blogs.msdn.com/b/visualstudio/archive/2015/02/05/using-angularjs-in-visual-studio-2013.aspx

    Download the angular.intellisense.js file and place it in the Program Files (x86)\Microsoft Visual Studio 12.0\JavaScript\References folder

    0 讨论(0)
  • 2020-11-30 02:27

    As @Balthasar pointed out (and in case you are using Resharper) you will need to enable intellisense from Visual Studio for it to work:

    Resharper -> options -> environment -> intellisense -> general, select 'Custom Intellisense' and for Javascript you can select Visual studio. Alternatively you can use the 'Visual Studio' statement completion (second option)

    0 讨论(0)
  • 2020-11-30 02:29

    I had the same issue. When I added angular, VS 2015 (RTM) modified my _references.js; basically it removed some of my lines in the file. When I added a reference for angula in my _references.js as below

    /// <reference path="lib/angular/angular.js" />

    I got my intellisense for Angular 1.4.3 in VS 2015!

    0 讨论(0)
  • 2020-11-30 02:31

    Visual Studio intellisense for AngularJS is extremely sentimental (a nice way of saying that it's most likely poorly developed).

    So, even if everything is well configured with the _references.js file, and you get intellisense for other libraries like jQUERY, you will most probably not get it for AngularJS.

    For example, in VS 2015 community, the below directive will not show intellisense for the $http angular object, although everything works fine with the code:

    In the image below, I add an empty array to the module (which means that the module will get created, and if another with the same name exists, it get overwritten), and intellisense starts working:

    Here is a snippet of the code for you to test yourself (try and add the empty array here):

    (function () {
        'use strict';
    
        angular
            .module('intellisence.sucks.directives')
            .directive('footer', footer);
    
        footer.$inject = ['$http'];
    
        function footer($http) {
    
            $http.
            var directive = {
                link: link,
                restrict: 'EA'
            };
            return directive;
    
            function link(scope, element, attrs) {
            }
        }
    
    })();


    PS: If you click on any folder on you project in the Solution Explorer and press Ctrl+Alt+A to add a new item, you get suggestion to add a AngularJs Directive, and If you do it, the Directive will be like the one I just showed you, without the empty array on the module declaration, so intellisence won't work with it. It won't work with the example that Microsoft gives to the users... Only works on the module creation, your first file and doesn't work from now on.

    0 讨论(0)
提交回复
热议问题