• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Declaring Classes in TypeScript Angular 2

September 23, 2017 by ProjectsGeek Leave a Comment

How to Declare Classes in TypeScript Angular 2

Classes in TypeScript

In this post we will see how to declare a class in TypeScript angular 2. In this below code window you can see we have declared class Point with two variables ‘x’ and ‘y’. We have one method also inside Point class which will print both the point values of object.

class Point {
    
        x: number;
        y: number;

        doSomething() {
            console.log('Point X: '+this.x);
            console.log('Point Y: '+this.y);
        }
    
    }

Initializing the Class in TypeScript

In this below code snippet we are creating one variable point with is of Type Point class. Then we are allocating memory or creating object of type Point by using new keyword like any other object oriented language.

let point: Point;
point = new Point();
point.x=1;
point.y=2;
point.doSomething();

We are using point variables to assign values to object variables ‘x’x and ‘y’. At the end we are calling doSomething() method of point object we just created. Below is the result of above code.

let point: Point;
point = new Point();
point.x=1;
point.y=2;
point.doSomething();

 

Other Projects to Try:

  1. Declaring Interface in TypeScript Angular 2
  2. Declaring Constructors in TypeScript Angular 2
  3. Public and Private Keywords
  4. TestPage
  5. Difference between VAR and LET Angular 2

Filed Under: Angular 2 Tagged With: Angular 2

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy