WebStorm 2016.3 Help

Using AngularJS

On this page:

Overview

WebStorm provides integration with the AngularJS framework, versions 1 and 2. This support involves:

  • AngularJS-aware code completion for ng directives (also including custom directives), controller and application names, and code insights for data bindings inside curly-brace expressions {{}}.
  • AngularJS-specific navigation:
    • Between the name of a controller name in HTML and its definition in JavaScript.
    • Between ngView or &routeProvider to the template.
    • Go To Symbol navigation for entities.
  • Quick documentation look-up by pressing Ctrl+Q, see Viewing Inline Documentation for details.
  • AngularJS router diagrams.

You can get AngularJS support in a WebStorm project in two ways:

  • Have WebStorm generate an AngularJS-specific project stub. WebStorm generates the Angular 2-specific project structure with all the required configuration files. See Generating an AngularJS Application Stub below on this page.
  • Create an Angular 2 project using Angular CLI, see Using Angular CLI.
  • Create an empty project and install AngularJS in it. This can be done either manually, by downloading the AngularJS framework or by means of the Bower package manager, see Installing and Removing Bower Packages..

    If you choose manual installation, you will need to configure AngularJS as a WebStorm JavaScript library. If you use Bower, this will be done automatically, without any steps from your side.

Before you start

Make sure the NodeJS and AngularJS plugins are enabled. The plugins are bundled with WebStorm and activated by default. If the plugins are not activated, enable them on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Generating an AngularJS application stub

WebStorm can generate a project stub for developing applications using AngularJS.

  1. Choose File | New Project on the main menu or click the New Project button on the Welcome screen. The New Project Dialog dialog box opens.
  2. In the left-hand pane, choose AngularJS.
  3. In the right-hand pane:
    1. In the Location text box, specify the path to the project folder where the project-related files will be stored.
    2. From the Version drop-down list, choose the branch https://github.com/angular/angular.js to download the project template from. By default, master if shown.
  4. When you click Create, WebStorm generates the Angular 2-specific project structure with all the required configuration files.
  5. Download the AngularJs dependencies that contain the AngularJS code and the tools that support development and testing.
    1. Launch the embedded Terminal by hovering your mouse pointer over /help/img/idea/2016.3/show_tool_window_bars.png in the lower left corner of WebStorm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
    2. Switch to the directory where NPM is stored or define a PATH variable for it so it is available from any folder, see Installing NodeJs.
    3. At the command line prompt, type the following command:
      npm install

    Learn more about the installation of dependencies in the Install Dependencies section of the readme.md file.

Creating an empty WebStorm project

  1. Choose File | New Project on the main menu or click the New Project button on the Welcome screen. The New Project Dialog dialog box opens.
  2. In the left-hand pane, choose Empty Project.
  3. In the Location text box, specify the path to the project folder where the project-related files will be stored.
  4. When you click Create, WebStorm creates and opens an empty project.

Configuring AngularJS coding assistance in an empty project manually

  1. Download the AngularJS framework at http://angularjs.org/.
  2. Open the empty project where you will use AngularJS.
  3. Configure AngularJS as a WebStorm JavaScript library, to let WebStorm recognize AngularJS-specific structures and provide full coding assistance:
    1. Open the Settings dialog box, and click JavaScript Libraries.
    2. In the Libraries area, click the Add button.
    3. In the New Library dialog box that opens, specify the name of the library.
    4. Click the Add button /help/img/idea/2016.3/new.png next to the list of library files and choose Attach Files or Attach Directory on the context menu, depending of whether you need separate files or an entire folder.
    5. Select the Angular.js or Angular.min.js, or an entire directory in the dialog box that opens. WebStorm returns to the New Library dialog box where the Name read-only field shows the name of the selected files or folder.
    6. In the Type field, specify which version you have downloaded and are going to add.
      • If you added Angular.js, choose Debug. This version is helpful in the development environment, especially for debugging.
      • If you added the minified Angular.min.js, choose Release. This version is helpful in the production environment because the file size is significantly smaller.
    Learn more at Configuring JavaScript Libraries.

Installing AngularJS in an empty project through NPM and Bower

  1. Open the empty project where you will use AngularJS.
  2. Download and install Node.js. This runtime environment is required for two reasons:
    • The Bower package manager is started through Node.js.
    • Node Package Manager (npm), which is a part of Node.js, is also the easiest way to download Bower.

    For details on using Node.js in WebStorm, see Node.js

  3. Install Bower as described in Using Bower Package Manager.
  4. If you are going to use the command line mode, make sure the following paths are added to the PATH variable:
    1. The path to the parent folder of the Node.js executable file.
    2. The path to the npm folder.
    3. The path to the parent folder of the Bower executable file.

    This enables you to launch the tools from any folder.

  5. Run Bower from WebStorm using the Bower page of the Settings dialog box.
    1. Open the Settings dialog box, and click JavaScript, then click Bower.
    2. On the Bower page that opens, the Packages area shows all the Bower-dependent packages that are currently installed on your computer, both at the global and at the project level. Click /help/img/idea/2016.3/new.png.
    3. In the Available Packages dialog box that opens, select the AngularJS package.
    4. Specify the installation mode:
      • To have the tool installed globally at the WebStorm level so it can be used in any WebStorm project, select the Options check box and type -g in the text box next to it.
      • To have the tool installed in the current project and thus restrict its use to this project, clear the Options check box.
    5. Optionally specify the product version and click Install Package to start installation.

Testing AngularJS using Protractor

WebStorm supports integration with the Protractor test framework. This support includes generation of the protractor.conf.js configuration file and starting of the Selenium Server.

  1. Install Protractor globally on your machine:

    Global installation makes a test framework available at the WebStorm level so it can be used in any WebStorm project. Moreover, during installation the parent folder of the test framework is automatically added to the PATH variable, which enables you to launch the test framework from any folder. To install the test framework globally, do one of the following:

    • Run the installation from the command line in the global mode:
      1. Launch the embedded Terminal by hovering your mouse pointer over /help/img/idea/2016.3/show_tool_window_bars.png in the lower left corner of WebStorm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
      2. Switch to the directory where NPM is stored or define a PATH variable for it so it is available from any folder, see Installing NodeJs.
      3. Type the following command at the command line prompt:
        npm install -g protractor

        The -g key makes the test framework run in the global mode. Because the installation is performed through NPM, the Protractor test framework is installed in the npm folder. Make sure this parent folder is added to the PATH variable. This enables you to launch the test framework from any folder.

        For more details on the NPM operation modes, see npm documentation. For more information about installing the Protractor test framework, see https://npmjs.org/package/protractor.

    • Run NPM from WebStorm using the Node.js and NPM page of the Settings dialog box.
      1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or WebStorm | Preferences for OS X, and click Node.js and NPM under Languages&Frameworks.
      2. On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click /help/img/idea/2016.3/new.png.
      3. In the Available Packages dialog box that opens, select the required package to install.
      4. Select the Options check box and type -g in the text box next to it.
      5. Optionally specify the product version and click Install Package to start installation.
  2. To download the necessary binaries, switch to the Terminal tool window and type the following command:
    webdriver-manager update
  3. Create a run configuration fo the type Protractor:
    1. Click the Add button /help/img/idea/2016.3/new.png on the toolbar and select the Protractor configuration type.
    2. In the dialog box that opens, specify the Node interpreter to use, the location of the protractor package, and the path to the protractor.conf.js configuration file. If you followed the standard installation, WebStorm detects all these paths and displays them in the corresponding fields. Apply the changes, if any, anf close the dialog box.
  4. To launch the tests:
    1. To launch the tests according to a run configuration, select the Protractor run/debug configuration from the list on the main toolbar.
      /help/img/idea/2016.3/ws_select_run_configuration.png
      Then click the Run button /help/img/idea/2016.3/run.png to the right of the list. The Selenium Server starts automatically without any steps from your side.
    2. View and analyze messages from the server in the <current_run_configuration_name> tab of the Run tool window.

See Also

Last modified: 1 December 2016