Angular 2 Example

Working with the Angular 2 Example Application

Hands-on learning is often the best way to learn a new technology. Create a new project with our custom SB Admin template to quickly get going with Angular 2. The template uses a responsive design and Bootstrap 4 to create a framework for development of admin panels, charts, web apps or dashboards. The example app is available in our Angular IDEWebclipse Eclipse plugin and MyEclipse Java EE IDE.

Back to Learning Center

Download Angular IDE


Using the Angular 2 Template in a New Project

To create a project using the example template, select the Use template check box from the New Angular 2 Project wizard. The initial release of Angular IDE includes a single template; future versions will include multiple Angular 2 templates.




When you click Finish, only a basic Eclipse project skeleton is created along with the template code. Before you can actually use this project, the project configuration must be completed—this could mean downloading and/or installing Node, NPM and the corresponding version of the Angular CLI into your project. You can observe detailed progress in the Terminal+ view. For additional details, see Understanding Angular CLIs.




Examining the Project Contents

Once the project is completely set up, let’s take a closer look at a few of its key contents:

src/app folder

This folder contains several Angular modules, the “meat” of your application. A module is a cohesive block of code, dedicated to an application domain, a workflow, or a closely related set of capabilities. This template application contains several dashboard modules, including modules for forms and charts, as well as login and signup modules.

Of special note is the root module (AppModule), which is in app.module.ts—your application is launched by bootstrapping this module.

Modules are accompanied by Angular 2 components, along with their corresponding templates and styles. A component controls a patch of screen, called a view—the component class contains application logic to support this view. The component’s template is a form of HTML that tells Angular how to render the component.

Finally, routes define how navigation takes place within our application, based on a URL pattern.


Code in this file initializes the platform that your application runs in, then uses the platform to bootstrap your AppModule.


Our Angular support is based on the Angular CLI. This file contains settings and instructions on how your Angular application is to be built, tested and deployed. For details, refer to Understanding Angular CLIs in the learning center.


This file contains your project’s TypeScript settings, controlling source locations, JavaScript targets (like ES5 or ES6), compilation, how types are resolved and several other settings. Several of these properties can be configured on your project’s TypeScript property page. For more on TypeScript and this configuration file, see Using TypeScript.


This is another TypeScript specific file, which primarily contains your project’s dependencies, listed as Node.js modules and their corresponding versions. package.json does contain other key project metadata as well, such as the name, description and version of your project, as well as scripts that are run at different stages of your project’s lifecycle. 

node_modules folder

This folder contains all the Node packages your project is dependent on—these are defined in package.json and downloaded by the Node Package Manager (npm).

protractor.conf.js and the e2e folder

Our template project uses Protractor and Jasmine, both end-to-end testing frameworks to test your application. The test framework is configured in protractor.conf.js while the actual tests are in the e2e folder.


Running & Debugging the Project

Now that we’ve had a chance to examine our project, let’s go ahead and deploy it!

Right-click your application in the Explorer and select Run As>Server for Angular CLI Project to build and deploy the project. A browser automatically opens with the app loaded. Once you log in (simply click Log in, the template does not validate credentials), the app should look like the screenshot below. 




Observe the Terminal+ view which indicates how your app is being built and deployed, including a list of deployed resources.




The Servers view lists all Angular projects in the workspace, including deployment state. You can choose to stop and start the server from here or even start a debug session. 




You can place a breakpoint in TypeScript, HTML or JavaScript files by simply double-clicking the ruler area. If you start a debug session, your application pauses when breakpoints are hit and you can step through the source in all files, even TypeScript.


Making Changes to the Application

While the app is running, several changes can be made without having to redo the run sequence. If you make a change and save it, Live Preview (tech that runs within Angular 2 applications) detects the change, rebuilds the app, and reloads the app in the browser automatically.

To see how this works, run your application and stay on the Login page in the browser. Now open the login.component.html file and on line #13, change placeholder=”Password” to placeholder=”Strong Password”. Save the file and observe the change is picked up (you’ll see activity in the terminal) and the page is automatically reloaded to now show “Strong Password” instead of just “Password”. Neat!

Now let’s make a bigger change, let’s add a chart covering “Interest in Modern Web Frameworks”. 

First, we’ll add a placeholder div for our new chart. Edit the chart.component.html file and add the following section just below the last div with class col-xl-6:


Now let’s create the new chart and fill it with some data. In chart.component.ts add the following code below the snowDepth chart. Observe how it’s linked to the modern-web placeholder we created earlier.


Save both edited files and observe the changes being rebuilt in the console. Our chart page is refreshed, and we see our new chart nicely rendered at the end of the page. Almost too easy!