{"id":14382,"date":"2025-05-15T19:32:21","date_gmt":"2025-05-15T19:32:21","guid":{"rendered":"https:\/\/kmfinfotech.com\/blogs\/creating-your-first-angular-application-a-beginners-tutorial\/"},"modified":"2025-05-15T19:32:21","modified_gmt":"2025-05-15T19:32:21","slug":"creating-your-first-angular-application-a-beginners-tutorial","status":"publish","type":"post","link":"https:\/\/kmfinfotech.com\/blogs\/creating-your-first-angular-application-a-beginners-tutorial\/","title":{"rendered":"Creating Your First Angular Application: A Beginner\u2019s Tutorial"},"content":{"rendered":"<p><br \/>\n<\/p>\n<header><\/header>\n<p><\/p>\n<article><\/p>\n<h2>Introduction<\/h2>\n<p><\/p>\n<p>Welcome to the world of Angular! Angular is a platform for building mobile and desktop web applications using TypeScript\/JavaScript and other languages. It provides a holistic framework for you to develop single-page applications that are dynamic, scalable, and maintainable.<\/p>\n<p><\/p>\n<p>This tutorial is geared towards beginners who wish to step into the realm of developing a basic Angular application. By the end of this guide, you will know how to initiate an Angular project, understand its basic components, and create your first Angular application.<\/p>\n<p><\/p>\n<h2>Prerequisites<\/h2>\n<p><\/p>\n<p>To follow along, you should have a basic understanding of HTML, CSS, and JavaScript. Additionally, you should have Node.js and npm (Node Package Manager) installed on your machine. You can verify this by running <code>node -v<\/code> and <code>npm -v<\/code> in your command line interface. If you haven&#8217;t installed them yet, head over to <a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noopener\">Node.js official website<\/a> and download the latest stable version.<\/p>\n<p><\/p>\n<h2>Setting Up Your Development Environment<\/h2>\n<p><\/p>\n<p>Before diving into application development, you need to set up your workspace. Below are steps to get started:<\/p>\n<p><\/p>\n<h3>Installing Angular CLI<\/h3>\n<p><\/p>\n<p>The Angular Command Line Interface (CLI) is a powerful tool that allows you to streamline your development workflow. To install Angular CLI, open your terminal or command line interface and type the following command:<\/p>\n<p><\/p>\n<pre><code>npm install -g @angular\/cli<\/code><\/pre>\n<p><\/p>\n<p>The above command will globally install Angular CLI on your machine.<\/p>\n<p><\/p>\n<h3>Creating a New Angular Project<\/h3>\n<p><\/p>\n<p>Once the CLI is installed, you can set up a new Angular project. Navigate to the directory where you want your project to reside and type the following command:<\/p>\n<p><\/p>\n<pre><code>ng new my-first-angular-app<\/code><\/pre>\n<p><\/p>\n<p>This initiates the creation of a new Angular project named <strong>my-first-angular-app<\/strong>. You\u2019ll be prompted to choose options about routing and style sheets, make your selections, and let the CLI configure the project.<\/p>\n<p><\/p>\n<h3>Serving Your Application<\/h3>\n<p><\/p>\n<p>After creating your project, the CLI will set up a basic Angular application structure for you. Navigate into your project directory:<\/p>\n<p><\/p>\n<pre><code>cd my-first-angular-app<\/code><\/pre>\n<p><\/p>\n<p>You can serve the application using:<\/p>\n<p><\/p>\n<pre><code>ng serve<\/code><\/pre>\n<p><\/p>\n<p>This command will build the application and start a local server at <code>http:\/\/localhost:4200<\/code>. Open your web browser and go to this URL. You should see the default Angular welcome page.<\/p>\n<p><\/p>\n<h2>Understanding Angular Project Structure<\/h2>\n<p><\/p>\n<p>Let&#8217;s take a look at the project structure generated by Angular CLI:<\/p>\n<p><\/p>\n<ul><\/p>\n<li><strong>e2e\/<\/strong>: Contains end-to-end tests.<\/li>\n<p><\/p>\n<li><strong>node_modules\/<\/strong>: Contains the npm packages we&#8217;re using.<\/li>\n<p><\/p>\n<li><strong>src\/<\/strong>: Contains the application code.<\/li>\n<p><\/p>\n<li><strong>angular.json<\/strong>: Configuration for Angular CLI.<\/li>\n<p><\/p>\n<li><strong>package.json<\/strong>: Handles npm package dependencies.<\/li>\n<p>\n        <\/ul>\n<p><\/p>\n<p>The <strong>src\/<\/strong> directory is where you will find the core files for your application:<\/p>\n<p><\/p>\n<ul><\/p>\n<li><strong>app\/<\/strong>: The application root directory.<\/li>\n<p><\/p>\n<li><strong>assets\/<\/strong>: Stores images and other assets.<\/li>\n<p><\/p>\n<li><strong>environments\/<\/strong>: Environment-specific settings.<\/li>\n<p><\/p>\n<li><strong>index.html<\/strong>: The main HTML file.<\/li>\n<p><\/p>\n<li><strong>main.ts<\/strong>: The entry point of the application.<\/li>\n<p><\/p>\n<li><strong>styles.css<\/strong>: Global styles.<\/li>\n<p>\n        <\/ul>\n<p><\/p>\n<h2>Building Your First Component<\/h2>\n<p><\/p>\n<p>Angular applications are composed of components. A component consists of three main elements: an HTML template, a CSS style, and a TypeScript class.<\/p>\n<p><\/p>\n<h3>Generating a Component<\/h3>\n<p><\/p>\n<p>Using Angular CLI, you can generate a new component easily. In the terminal, run the following command:<\/p>\n<p><\/p>\n<pre><code>ng generate component hello-world<\/code><\/pre>\n<p><\/p>\n<p>This command will create a new directory <strong>hello-world\/<\/strong> in <strong>src\/app\/<\/strong>, containing the following files:<\/p>\n<p><\/p>\n<ul><\/p>\n<li><code>hello-world.component.ts<\/code> &#8211; The TypeScript file defining the component class.<\/li>\n<p><\/p>\n<li><code>hello-world.component.html<\/code> &#8211; The template file.<\/li>\n<p><\/p>\n<li><code>hello-world.component.css<\/code> &#8211; The CSS styles specific to the component.<\/li>\n<p><\/p>\n<li><code>hello-world.component.spec.ts<\/code> &#8211; The test file.<\/li>\n<p>\n        <\/ul>\n<p><\/p>\n<h3>Editing the Hello World Component<\/h3>\n<p><\/p>\n<p>Open the <code>hello-world.component.html<\/code> file and add a simple message:<\/p>\n<p><\/p>\n<pre><code>&lt;h1&gt;Hello World!&lt;\/h1&gt;<\/code><\/pre>\n<p><\/p>\n<p>Next, modify <code>app.component.html<\/code> to include the <code>hello-world<\/code> component:<\/p>\n<p><\/p>\n<pre><code>&lt;app-hello-world&gt;&lt;\/app-hello-world&gt;<\/code><\/pre>\n<p><\/p>\n<p>Save your changes and check your application in the browser. You should see the &#8220;Hello World!&#8221; heading displayed.<\/p>\n<p><\/p>\n<h2>Adding Interactivity<\/h2>\n<p><\/p>\n<p>Components can hold data and respond to user actions. Let&#8217;s add some interactivity by creating a button that changes a message when clicked.<\/p>\n<p><\/p>\n<h3>Updating Component Class<\/h3>\n<p><\/p>\n<p>Edit the <code>hello-world.component.ts<\/code> file to include a message and a method to change it:<\/p>\n<p><\/p>\n<pre><code>import { Component } from '@angular\/core';<br>@Component({<br \/>\n  selector: 'app-hello-world',<br \/>\n  templateUrl: '.\/hello-world.component.html',<br \/>\n  styleUrls: ['.\/hello-world.component.css']<br \/>\n})<br \/>\nexport class HelloWorldComponent {<br \/>\n  message: string = 'Hello World!';<br>changeMessage() {<br \/>\n    this.message = 'You clicked the button!';<br \/>\n  }<br \/>\n}<br \/>\n        <\/code><\/pre>\n<p><\/p>\n<h3>Updating Template<\/h3>\n<p><\/p>\n<p>Modify the <code>hello-world.component.html<\/code> to include a button and display the message:<\/p>\n<p><\/p>\n<pre><code>&lt;h1&gt;{{ message }}&lt;\/h1&gt;<br \/>\n&lt;button (click)=\"changeMessage()\"&gt;Click me&lt;\/button&gt;<br \/>\n        <\/code><\/pre>\n<p><\/p>\n<p>With these changes, when you click the button, the message will update!<\/p>\n<p><\/p>\n<h2>Styling Your Application<\/h2>\n<p><\/p>\n<p>Styling in Angular can be handled through component-specific styles or global styles. Let&#8217;s add some basic styling.<\/p>\n<p><\/p>\n<h3>Adding Component Styles<\/h3>\n<p><\/p>\n<p>Edit the <code>hello-world.component.css<\/code> to style the button and heading:<\/p>\n<p><\/p>\n<pre><code>h1 {<br \/>\n  color: #1976d2;<br \/>\n}<br>button {<br \/>\n  background-color: #1976d2;<br \/>\n  color: white;<br \/>\n  border: none;<br \/>\n  padding: 0.5em 1em;<br \/>\n  cursor: pointer;<br \/>\n  margin-top: 10px;<br \/>\n}<br>button:hover {<br \/>\n  background-color: #155a9e;<br \/>\n}<br \/>\n        <\/code><\/pre>\n<p><\/p>\n<h2>Conclusion<\/h2>\n<p><\/p>\n<p>Congratulations! You&#8217;ve successfully created your first Angular application, built a component, and added interactivity and styling to it. Angular is a vast framework with many capabilities, and this tutorial is just the beginning of your journey. As you advance, you\u2019ll discover Angular&#8217;s powerful features such as routing, services, and state management through RxJS.<\/p>\n<p><\/p>\n<p>Continue exploring and practicing by adding new components, creating services for shared data, and experimenting with Angular\u2019s extensive CLI commands. Happy coding!<\/p>\n<p>\n    <\/article>\n<p><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Introduction Welcome to the world of Angular! Angular is a platform for building mobile and desktop web applications using TypeScript\/JavaScript and other languages. It provides a holistic framework for you to develop single-page applications that are dynamic, scalable, and maintainable. This tutorial is geared towards beginners who wish to step into the realm of developing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":14383,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[132],"tags":[254,110,210,303,405],"class_list":["post-14382","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-app","tag-angular","tag-application","tag-beginners","tag-creating","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/posts\/14382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/comments?post=14382"}],"version-history":[{"count":0,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/posts\/14382\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/media\/14383"}],"wp:attachment":[{"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/media?parent=14382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/categories?post=14382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kmfinfotech.com\/blogs\/wp-json\/wp\/v2\/tags?post=14382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}