PhpStorm 2018.1 Help

AngularJS

PhpStorm provides integration with the AngularJS framework also known as Angular 1. 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 in HTML and its definition in JavaScript.
    • Between ngView or &routeProvider and the template.
    • Go To Symbol navigation for entities.
  • A collection of AngularJS built-in live templates.
  • Quick documentation look-up by pressing Ctrl+Q.
  • AngularJS ui-router diagram.

Before you start

  1. Install Node.js and configure it as a local Node.js interpreter.
  2. Install and enable the AngularJS plugin on the Plugins page as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

Introduction

You can get AngularJS support in a PhpStorm project in the following ways:

Creating an AngularJS project using a seed project

  1. Choose File | New Project on the main menu or click Create New Project on the Welcome screen. The Create New Project Dialog opens.
  2. In the left-hand pane, choose AngularJS.
  3. In the right-hand pane, specify the path to the folder where the project-related files will be stored.
  4. When you click Create, PhpStorm generates the AngularJS-specific project structure with all the required configuration files based on the AngularJS seed project

To download AngularJS dependencies, do one of the following:

  • Open the embedded Terminal (View | Tool Windows | Terminal) and type npm install at the command prompt.
  • Choose Run 'npm install' on the context menu of the package.json file in your project root.

Configuring AngularJS support in a project

If you already have Angular sources in your project (for example, in the bower_components folder), just open your project and start working. If these sources are excluded from project, then you only need to configure AngularJS as a JavaScript library.

If you do not have any previously downloaded AngularJS sources, create an empty project, and then install AngularJS in it either manually, by downloading the AngularJS framework, or using the Bower package manager.

To create an empty PhpStorm project

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

To configure 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 PhpStorm JavaScript library, to let PhpStorm recognize AngularJS-specific structures and provide full coding assistance:
    1. Open the Settings/Preferences 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 new 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. PhpStorm 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 from Configuring JavaScript Libraries.

To install AngularJS in an empty project through Bower

  1. Open the empty project where you will use AngularJS.
  2. InstallNode.js.
  3. Install Bower as described in Bower.
  4. Open the embedded Terminal (View | Tool Windows | Terminal) and type bower install angular at the command prompt to install the package in the current project.

Using AngularJS Router state diagrams

You can see a diagram illustrating the relations between views, states, and templates in AngularJS applications that use ui-router.

To generate and view a diagram

  • Open the desired file in the editor, and then choose Diagrams | Show AngularJS ui-router State Diagram on the context menu. PhpStorm generates a diagram and shows it in a separate editor tab.

To navigate from an element in the diagram to the code that implements this element

  • Select it and choose Jump to Source on the context menu.
Last modified: 27 July 2018

See Also