Using AngularJS
On this page:
- Overview
- Before you start
- Generating an AngularJS application stub
- Creating an empty PyCharm project
- Configuring AngularJS coding assistance in an empty project manually
- Installing AngularJS in an empty project through NPM and Bower
- Testing AngularJS using Protractor
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:
- Quick documentation look-up by pressing Ctrl+Q, see Viewing Inline Documentation for details.
- AngularJS router diagrams.
You can get AngularJS support in a PyCharm project in two ways:
- Have PyCharm generate an AngularJS-specific project stub. PyCharm 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 PyCharm JavaScript library. If you use Bower, this will be done automatically, without any steps from your side.
Before you start
- 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.
- 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.
Generating an AngularJS application stub
PyCharm can generate a project stub for developing applications using AngularJS.
- Choose on the main menu or click the New Project button on the Welcome screen. The New Project Dialog dialog box opens.
- In the left-hand pane, choose AngularJS.
-
In the right-hand pane:
- In the Location text box, specify the path to the project folder where the project-related files will be stored.
-
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.
- When you click Create, PyCharm generates the Angular 2-specific project structure with all the required configuration files.
-
Download the AngularJs dependencies that contain the AngularJS code and the tools that support development and testing.
-
Launch the embedded Terminal
by hovering your mouse pointer over
in the lower left corner of PyCharm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
-
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. -
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. -
Launch the embedded Terminal
by hovering your mouse pointer over
Creating an empty PyCharm project
- Choose on the main menu or click the New Project button on the Welcome screen. The New Project Dialog dialog box opens.
- In the left-hand pane, choose Empty Project.
- In the Location text box, specify the path to the project folder where the project-related files will be stored.
- When you click Create, PyCharm creates and opens an empty project.
Configuring AngularJS coding assistance in an empty project manually
- Download the AngularJS framework at http://angularjs.org/.
- Open the empty project where you will use AngularJS.
- Configure AngularJS as a PyCharm JavaScript library, to let PyCharm recognize AngularJS-specific structures and provide full coding assistance:
- Open the Settings dialog box, and click JavaScript Libraries.
- In the Libraries area, click the Add button.
- In the New Library dialog box that opens, specify the name of the library.
-
Click the Add button
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.
-
Select the
Angular.js
orAngular.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. -
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.
-
If you added
Installing AngularJS in an empty project through NPM and Bower
- Open the empty project where you will use AngularJS.
-
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
- Install Bower as described in Using Bower Package Manager.
-
If you are going to use the command line mode, make sure the following paths are added to the PATH variable:
- The path to the parent folder of the Node.js executable file.
-
The path to the
npm
folder. - The path to the parent folder of the Bower executable file.
This enables you to launch the tools from any folder.
-
Run Bower from PyCharm using the Bower page of the Settings
dialog box.
- Open the Settings dialog box, and click JavaScript, then click Bower.
-
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
.
-
In the Available Packages dialog box that opens, select the
AngularJS
package. - Specify the installation mode:
- Optionally specify the product version and click Install Package to start installation.
Testing AngularJS using Protractor
PyCharm supports integration with the Protractor test framework.
This support includes generation of the protractor.conf.js
configuration file and
starting of the Selenium Server.
-
Install Protractor globally on your machine:
Global installation makes a test framework available at the PyCharm level so it can be used in any PyCharm 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:
-
Launch the embedded Terminal
by hovering your mouse pointer over
in the lower left corner of PyCharm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
-
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. -
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 thenpm
folder. Make sure this parent folder is added to thePATH
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.
-
Launch the embedded Terminal
by hovering your mouse pointer over
-
Run NPM from PyCharm using the Node.js and NPM page of the Settings dialog box.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for OS X, and click Node.js and NPM under Languages&Frameworks.
-
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
.
- In the Available Packages dialog box that opens, select the required package to install.
-
Select the Options check box and type
-g
in the text box next to it. - Optionally specify the product version and click Install Package to start installation.
-
Run the installation from the command line in the global mode:
-
To download the necessary binaries, switch to the Terminal tool window and type the following command:
webdriver-manager update
-
Create a run configuration fo the type Protractor:
-
Click the Add button
on the toolbar and select the Protractor configuration type.
-
In the dialog box that opens, specify the Node interpreter to use, the location of the
protractor
package, and the path to theprotractor.conf.js
configuration file. If you followed the standard installation, PyCharm detects all these paths and displays them in the corresponding fields. Apply the changes, if any, anf close the dialog box.
-
To launch the tests:
-
To launch the tests according to a run configuration, select the
Protractor run/debug configuration from the list on the main toolbar.
Then click the Run button
to the right of the list. The Selenium Server starts automatically without any steps from your side.
- View and analyze messages from the server in the <current_run_configuration_name> tab of the Run tool window.
-
To launch the tests according to a run configuration, select the
Protractor run/debug configuration from the list on the main toolbar.
Then click the Run button