PyCharm 2016.2 Help

Using AngularJS

On this page:

Overview

PyCharm 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.

Before you start

  1. Install and enable the NodeJS plugin. The plugin is not bundled with PyCharm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. The plugin is not bundled with PyCharm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
  2. Make sure the AngularJS plugin is enabled. The plugin is bundled with PyCharm and activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Setting up AngularJS support in a PyCharm project

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

  • Create an empty project and install AngularJS in it. This can be done either manually, by downloading the AngularJS framework and 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 PyCharm JavaScript library. If you use Bower, this will be done automatically, without any steps from your side.

  • Have PyCharm generate a stub of an AngularJS-specific project. PyCharm sets up the AngularJS-specific project structure and generates the bower.json and package.json files with the definitions of all the necessary dependencies. See Generating an AngularJS Application Stub below on this page.

Creating an empty PyCharm project for 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 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, PyCharm creates and opens an empty project.

Installing AngularJS manually in an empty project

  1. Download the AngularJS framework at http://angularjs.org/.
  2. Open the empty project where you will use AngularJS.
  3. Configure AngularJS as a PyCharm JavaScript library, to let PyCharm 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 add 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. PyCharm 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 PyCharm, see Node.js You can also define Node.js as an external tool, as described in the section Configuring third-party tools. This approach is helpful, when you need facilities that are missing in the plugin, for example, the possibility to pass certain parameters as wildcards.

  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. Install and enable the NodeJS and AngularJS repository plugins. The plugins are not bundled with PyCharm, but they can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. Once enabled, the plugins are available at the IDE level, that is, you can use it in all your PyCharm projects.
  6. Run Bower from PyCharm 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 add.
    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 PyCharm level so it can be used in any PyCharm 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.

Generating an AngularJS application stub

PyCharm 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, PyCharm sets up the AngularJS-specific project structure and generates the bower.json and package.json files with the definitions of all the necessary dependencies.
  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 show_tool_window_bars in the lower left corner of PyCharm 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.

See Also

Last modified: 23 November 2016