Skip to main content

Angular - Tutorial Part - 1 Application shell "Tour of languages"

The Application Shell

Install the Angular CLI

Install the Angular CLI, if you haven't already done so.
npm install -g @angular/cli

Create a new application

Create a new project named angular-tour-of-languages with this CLI command.
ng new angular-tour-of-languages


The Angular CLI generated a new project with a default application and supporting files.

Serve the application

Go to the project directory and launch the application.
cd angular-tour-of-heroes
ng serve --open
The ng serve command builds the app, starts the development server, watches the source files, and rebuilds the app as you make changes to those files.The --open flag opens a browser to http://localhost:4200/.

You should see the app running in your browser.

Angular components

The page you see is the application shell. The shell is controlled by an Angular component named AppComponent.
Components are the fundamental building blocks of Angular applications. They display data on the screen, listen for user input, and take action based on that input.

Change the application title

Open the project in your favorite editor or IDE and navigate to the src/app folder.
You'll find the implementation of the shell AppComponent distributed over three files:
  1. app.component.ts— the component class code, written in TypeScript.
  2. app.component.html— the component template, written in HTML.
  3. app.component.css— the component's private CSS styles.
Open the component class file (app.component.ts) and change the value of the title property to 'Tour of Heroes'.app.component.ts (class title property)

title = 'Tour of Heroes';
Open the component template file (app.component.html) and delete the default template generated by the Angular CLI. Replace it with the following line of HTML.app.component.html (template)

<h1>{{title}}</h1>
The double curly braces are Angular's interpolation binding syntax. This interpolation binding presents the component's title property value inside the HTML header tag.

The browser refreshes and displays the new application title.

Add application styles

Most apps strive for a consistent look across the application. The CLI generated an empty styles.css for this purpose. Put your application-wide styles there.
Here's an excerpt from the styles.css for the Tour of Languages sample app.


src/styles.css (excerpt)

  1. /* Application-wide Styles */
  2. h1 {
  3. color: #369;
  4. font-family: Arial, Helvetica, sans-serif;
  5. font-size: 250%;
  6. }
  7. h2, h3 {
  8. color: #444;
  9. font-family: Arial, Helvetica, sans-serif;
  10. font-weight: lighter;
  11. }
  12. body {
  13. margin: 2em;
  14. }
  15. body, input[text], button {
  16. color: #888;
  17. font-family: Cambria, Georgia;
  18. }
  19. /* everywhere else */
  20. * {
  21. font-family: Arial, Helvetica, sans-serif;
  22. }

Final code review

The source code for this tutorial and the complete Tour of Languages global styles are available in the live example / download example.
Here are the code files discussed on this page.
src/app/app.component.ts
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'Tour of Heroes'; }

src/app/app.component.html
<h1>{{title}}</h1>

src/styles.css (excerpt)
  1. /* Application-wide Styles */
  2. h1 {
  3. color: #369;
  4. font-family: Arial, Helvetica, sans-serif;
  5. font-size: 250%;
  6. }
  7. h2, h3 {
  8. color: #444;
  9. font-family: Arial, Helvetica, sans-serif;
  10. font-weight: lighter;
  11. }
  12. body {
  13. margin: 2em;
  14. }
  15. body, input[text], button {
  16. color: #888;
  17. font-family: Cambria, Georgia;
  18. }
  19. /* everywhere else */
  20. * {
  21. font-family: Arial, Helvetica, sans-serif;
  22. }

Summary

  • You created the initial application structure using the Angular CLI.
  • You learned that Angular components display data.
  • You used the double curly braces of interpolation to display the app title.

Comments

Popular posts from this blog

Scenario : Cloud Computing

ASP.NET Core - MVC Setup

Here we will set up the MVC framework in our FirstAppDemo application. We will proceed by building a web application on top of the ASP.NET Core, and more specifically, the ASP.NET Core MVC framework. We can technically build an entire application using only middleware, but ASP.NET Core MVC gives us the features that we can use to easily create HTML pages and HTTP-based APIs. To setup MVC framework in our empty project, follow these steps − Install the  Microsoft.AspNet.Mvc  package, which gives us access to the assemblies and classes provided by the framework. Once the package is installed, we need to register all of the services that ASP.NET MVC requires at runtime. We will do this inside the  ConfigureServices  method. Finally, we need to add middleware for ASP.NET MVC to receive requests. Essentially this piece of middleware takes an HTTP request and tries to direct that request to a C# class that we will write. Step 1  − Let us go to the NuGet package manager by ri

SQL Server Tutorial - Date functions

1. Get month names with month numbers: In this query we will learn about  How to get all month names with month number in SQL Server . I have used this query to bind my dropdownlist with month name and month number. 1 2 3 4 5 6 7 8 9 10 11 12 ;WITH months(MonthNumber) AS (      SELECT 0      UNION ALL      SELECT MonthNumber+1      FROM months      WHERE MonthNumber < 12 ) SELECT DATENAME(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) AS [MonthName],Datepart(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) AS MonthNumber FROM months ORDER BY Datepart(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) ; 2. Get name of current month: In this query we will learn about  How to get name of current month in SQL Server . 1 select DATENAME(MONTH, GETDATE()) AS CurrentMonth 3. Get name of day: In this query we will learn about  How to get name of day in SQL Server . 1 select DATENAME(WEEKDAY, GETDATE()) AS TodayI