Using AngularJS
On this page:
- Overview
- Before you start
- Setting up AngularJS support in a PhpStorm project
- Generating an AngularJS application stub
Overview
PhpStorm 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.
Before you start
Make sure the NodeJS and AngularJS plugins are installed and enabled. The plugins are not bundled with PhpStorm, 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 PhpStorm projects.
Setting up AngularJS support in a PhpStorm project
You can get AngularJS support in a PhpStorm 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 PhpStorm JavaScript library. If you use Bower, this will be done automatically, without any steps from your side.
-
Have PhpStorm generate a stub of an AngularJS-specific project.
PhpStorm sets up the AngularJS-specific project structure and generates the
bower.json
andpackage.json
files with the definitions of all the necessary dependencies. See Generating an AngularJS Application Stub below on this page.
Creating an empty PhpStorm project for 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 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, PhpStorm creates and opens an empty project.
Installing AngularJS manually in an empty project
- Download the AngularJS framework at http://angularjs.org/.
- Open the empty project where you will use AngularJS.
- Configure AngularJS as a PhpStorm JavaScript library, to let PhpStorm 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. PhpStorm 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 PhpStorm, 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.
- 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.
- Install and enable the NodeJS and AngularJS repository plugins. The plugins are not bundled with PhpStorm, 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 PhpStorm projects.
-
Run Bower from PhpStorm 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.
Generating an AngularJS application stub
PhpStorm 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,
PhpStorm sets up the AngularJS-specific project structure and generates the
bower.json
andpackage.json
files with the definitions of all the necessary dependencies. -
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 PhpStorm 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