Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Recruitment

    Enhancing Employee Retention: The Critical Role of Recruiters

    Startups

    Strategic Approaches to Navigating Startup Market Competition

    Wiki

    Роли внутри проектов

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Monday, September 29
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / Angular / How I Got Started with Angular and TypeScript
    Angular

    How I Got Started with Angular and TypeScript

    Ho-Hang JohnBy Ho-Hang JohnFebruary 4, 2020Updated:March 11, 2020No Comments6 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    How I Got Started with Angular and TypeScript
    How I Got Started with Angular & TypeScript
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    How I Got Started with Angular & TypeScript
    How I Got Started with Angular and TypeScript

    Learning Angular isn’t the easiest thing in the world. It takes a while to learn it. However, once I understood the basic architecture of Angular, creating apps with it became easier. In this article, I’ll show how I learned Angular and TypeScript without knowledge of either.

    The Beginning

    When I knew nothing, I started by writing practice apps with Angular. The fastest way to get started is using the Angular CLI. I created a basic app first by install the Angular CLI by running:

    npm install -g @angular/cli

    Then I created my first Angular app project by running:

    ng new practice-app

    In the Angular CLI, I chose to include routing. And choose to include CSS so reduce the amount of things I have to learn. Then we start our app by going to the practice-app  folder and then run ng serve  to start the development server that comes with Angular CLI.

    Writing Some Basic Angular Code

    Now that I have started our Angular CLI development server, I will write some code.

    Showing Some Data on the Screen

    I first practiced how to display some dynamic data on the screen from components. First, I went to app.component.ts . I see that it has the following content generated by the Angular CLI:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'practice-app';
    }

    I start by adding some fields to the AppComponent class, which changed the code to:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      firstName = 'Jane';
      lastName = 'Smith';
    }

    Then I went to app.component.html, which has:

    <!--The content below is only a placeholder and can be replaced.-->
    <div style="text-align:center">
      <h1>
        Welcome to {{ title }}!
      </h1>
      <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
    </div>
    <h2>Here are some links to help you start: </h2>
    <ul>
      <li>
        <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
      </li>
      <li>
        <h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
      </li>
      <li>
        <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
      </li>
    </ul>
    
    <router-outlet></router-outlet>

    generated by Angular CLI. I changed that to:

    <p>{{firstName}} {{lastName}}</p>
    

    Then I see ‘Jane Smith’ on the screen. Next, I learn about adding the constructor  method into the component class to initialize the component. I changed the code in app.component.ts to:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      firstName: string;
      lastName: string;
    
      constructor() {
        this.firstName = 'Jane';
        this.lastName = 'Smith';
      }
    }

    As we can see, whatever property of this  can be shown in the corresponding HTML template if we put then between curly braces and without the this. So this.firstName  in the component code becomes {{firstName}}  in our HTML template. Likewise, we can display array items on the screen. The difference is that we have to use the *ngFor  directive in our template to loop through the items and display them. To display a list of objects, first we have to create an interface to indicate the structure of the array entry that we want to display. We run ng g interface Person  to create a Person  interface in the person.ts  file.

    Read More:  How to Create a Personal Blogging Website: Back-End (Flask/Python) #1

    In person.ts, we replace the existing code with:

    export interface Person {
        name: string;
    }

    Then we go back to app.component.ts and change the file to:

    import { Component } from '@angular/core';
    import { Person } from './person';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      persons: Person[];
    
      constructor() {
        this.persons = [
          { name: 'Jane' },
          { name: 'John' },
          { name: 'Mary' },
        ]
      }
    }

    In the code above, we have the names  array, which is of type Person[] . It’s an array of Person  objects, where Person  is the interface that we just created. The Person  interface specified that our Person  object has the name property and it’s of type string.

    Then we go to app.component.html and change it to:

    <p  *ngFor='let p of persons'>{{p.name}}</p>

    Then we get:

    Jane
    
    John
    
    Mary

    displayed on the screen. In the code above, we have the following expression in our *ngFor directive:

    let p of persons

    p has the entry from the this.persons  array in app.component.html  and {{p.name}}  returns the name  property of p  so that we can display the name from there.

    Conditional Display with NgIf

    Next, I learned how to conditionally display items with the *ngIf  directive. It takes an expression that returns a truthy or falsy value. I changed app.component.ts to:

    import { Component } from '@angular/core';
    import { Person } from './person';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      displayName: boolean = false;
    }

    Then I changed app.component.html to:

    <p *ngIf='displayName'>Jane</p>

    Now I see nothing on the screen. I realized that this.displayName  in app.component.ts  set to false  hides the name if we write *ngIf=’displayName’ . Then I set this.displayName  to true  in app.component.ts. Now I see the ‘Jane’ displayed without changing app.component.html . This means that the content is displayed if displayName is true.

    Template Syntax

    After looking at the Angular documentation, the curly braces is for interpolating data from our component file in our template. Anything between the double curly braces are interpolated. We can put any valid HTML in our template, along with variables, some expressions, and directive in our template code. I put expression straight into our template as follows:

    Read More:  How to Upload Images to a Cloud Storage(Imgur) in an Angular Application

    app.component.html:

    {{1 + 1}}
    

    Then I see 2 on the screen. It evaluated the 1 + 1 expression and returned the result. However, I after trying other things like assigning variables, operators, chaining expressions with ; or ,, increment and decrement operators, I see that they all give me errors. Bitwise operators also didn’t work for me. Also, I discovered that I can define reference variables in templates to access the element directly.

    I changed app.component.html to:

    <label>
      {{input.name}}:
      <input #input name='foo'>
    </label>

    I see that foo:  is besides the input box. So now I know that #input  sets the name of my input element to input . Then I can access its DOM properties directly, as I did with input.name  to get the value of the name  attribute that I’ve set.

    Conclusion

    I learned the most basic parts of Angular by trying various constructs myself. I created the app by running the Angular CLI. First I tried to display component field values on the screen with double curly braces in the template. Then I tried playing with component class fields and basic directives like *ngIf  to conditionally display content and *ngFor  to display an array of items. Finally, I set an HTML element to a variable and then accessed its attributes directly in the template.


    Repos:

    https://bitbucket.org/hauyeung/angular-basic-app-1/src/master/

    https://bitbucket.org/hauyeung/angular-basic-app-2/src/master/

    https://bitbucket.org/hauyeung/angular-basic-app-3/src/master/

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ho-Hang John

      Related Posts

      Handling HEIC Images in Angular: A Comprehensive Tutorial

      April 20, 2023

      A comprehensive insight of the Angular Structure

      October 15, 2020

      How to Create a Personal Blogging Website: Front-End (Angular) #2

      March 2, 2020
      Leave A Reply Cancel Reply

      You must be logged in to post a comment.

      Stay In Touch
      • Facebook
      • Twitter
      • Pinterest
      • Instagram
      • YouTube
      • Vimeo
      Don't Miss
      Comics November 15, 2016

      True Freelancer’s story

      We are looking forward to meeting you on our website blog.soshace.com

      How to Stay Motivated While Working Remotely/Freelancing?

      February 8, 2020

      The Importance of Showing Off Your Soft Skills

      March 5, 2019

      A comprehensive insight of the Angular Structure

      October 15, 2020

      Categories

      • AI & Automation
      • Angular
      • ASP.NET
      • AWS
      • B2B Leads
      • Beginners
      • Blogs
      • Business Growth
      • Case Studies
      • Comics
      • Consultation
      • Content & Leadership
      • CSS
      • Development
      • Django
      • E-commerce & Retail
      • Entrepreneurs
      • Entrepreneurship
      • Events
      • Express.js
      • Facebook Ads
      • Finance & Fintech
      • Flask
      • Flutter
      • Franchising
      • Funnel Strategy
      • Git
      • GraphQL
      • Home Services Marketing
      • Influencer & Community
      • Interview
      • Java
      • Java Spring
      • JavaScript
      • Job
      • Laravel
      • Lead Generation
      • Legal & Compliance
      • LinkedIn
      • Machine Learning
      • Marketing Trends
      • Medical Marketing
      • MSP Lead Generation
      • MSP Marketing
      • NestJS
      • Next.js
      • Node.js
      • Node.js Lessons
      • Paid Advertising
      • PHP
      • Podcasts
      • POS Tutorial
      • Programming
      • Programming
      • Python
      • React
      • React Lessons
      • React Native
      • React Native Lessons
      • Recruitment
      • Remote Job
      • SaaS & Tech
      • SEO & Analytics
      • Soshace
      • Startups
      • Swarm Intelligence
      • Tips
      • Trends
      • Vue
      • Wiki
      • WordPress
      Top Posts

      Fortune 500 top hiring trends in 2019. How big corporations hire top talents?

      JavaScript September 24, 2018

      Adding backend to CodePen snippet using Python/Django | Question-Answering Application

      Python April 28, 2020

      Effective Strategies to Boost B2B Lead Conversion Rates

      B2B Leads December 4, 2024

      An Introduction to Finite State Machines: Simplifying React State Management with State Machines

      JavaScript February 2, 2021

      Subscribe to Updates

      Get The Latest News, Updates, And Amazing Offers

      About Us
      About Us

      Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

      7901 4th St N, Suite 28690
      Saint Petersburg, FL 33702-4305
      Phone: 1(877)SOSHACE

      Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
      Our Picks
      Wiki

      Роль Менеджера Продуктов

      JavaScript

      Form Validation in Vue Using Vuelidate

      JavaScript

      Minimize Downtime by Creating a Health-check for Your NodeJS Application

      Most Popular

      2. Уроки Express.js . Логгер, Конфигурация, Шаблонизация с EJS. Часть 1.

      Programming

      Tech Blogging for Web Developers in 2019: Why? Which Platform? How to Start Your Own Tech Blog?

      Blogs

      Using Feature Flags for A/B Testing & Optionally Enable/Disable Features in Your NodeJS Project

      JavaScript
      © 2025 Soshace Digital.
      • Home
      • About
      • Services
      • Contact Us
      • Privacy Policy
      • Terms & Conditions

      Type above and press Enter to search. Press Esc to cancel.