Sunday, September 9, 2018

Part 4- How to use various Data types in Angular 5 Application - TypeScript Data Types



In this tutorial, You will learn about how to use data types in Angular 5 application. Here we will talk about the  useful data types available in TypeScript. If you are new to Angular then please also visit below Links Part1: Create your first Angular 5 application and Part2 :  How does Angular 5 works?

Useful Data Types( TypeScript)

  1. String
  2. Number 
  3. Array
  4. Any
  5. Boolean
  6. Tuple
  7. object
  8. Null
  9. void

Component.ts Code


import { Component } from '@angular/core';
import { Employee } from './Employee';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
name: string;
age: number;
numArray: number[];
strArray: Array<string>;
dynamicValue: any;
IsTrue: boolean;
tupleVal: [string, number, boolean];
student: object;
employee: Employee;
constructor() {
this.name="Ashish";
this.age = 52;
this.numArray = [10, 11, 20];
this.strArray = ["Ashish", "Kumar", "Tiwary"];
this.dynamicValue = 10000;
this.IsTrue = false;
this.tupleVal = ["Ashish", 45, true];
this.student = { name: "Ashish", age: "45", email: "a@b.com" }
this.employee = new Employee();
this.employee.Name = "Rose";
this.employee.Salary = 52000;
this.employee.Department = "Development";
this.employee.IsActive = true;
}
Test(mynum: number,str:string): number {
return
}
}

Component.Html Code


<div style="margin:3% 10% 10% 10%;border:2px solid gainsboro;padding:2% 2% 2% 2%; ">
<ul>
<li>Name: {{name}}</li>
<li>Age:{{age}}</li>
<li>Number Array: {{numArray}}</li>
<li>String Array: {{strArray}}</li>
<li>Dynamic value: {{dynamicValue}}</li>
<li>Is true: {{IsTrue}}</li>
<li>Tuple:{{tupleVal}}</li>
<li>Student Object:{{student|json}}</li>
<li>Employee Class: {{employee|json}}</li>
</ul>
<ul>
<li *ngFor="let arr of strArray">
{{arr}}
</li>
</ul>
<router-outlet></router-outlet>
</div>

Employee.ts Class


export class Employee {
Name: string;
Salary: number;
Department: string;
IsActive: boolean;
}



Output

For more details please watch above video.

You are done! Please share, Like, Comment

8 comments:

MS Dynamics said...

Thanks for sharing the valuable information.
Angular JS Online training

Angular JS training in hyderabad

Sowmiya R said...

I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.

Oracle Training in Chennai | Certification | Online Training Course | Oracle Training in Bangalore | Certification | Online Training Course | Oracle Training in Hyderabad | Certification | Online Training Course | Oracle Training in Online | Oracle Certification Online Training Course | Hadoop Training in Chennai | Certification | Big Data Online Training Course

Nikhil said...

Improve coding skills with professional
Python training.
Includes hands-on practice.
Best for career growth.

ONLINE IT GURU said...

"Boost your career with our salesforce admin course online designed for beginners and professionals alike. Learn to manage Salesforce efficiently and gain industry-recognized skills from anywhere."

ONLINE IT GURU said...

Learn platform skills, configuration, and automation with a salesforce admin course onlinedesigned for real-world business needs.

ONLINE IT GURU said...

This salesforce admin traininghelps build real-world expertise for configuring workflows, reports, and automation efficiently.

ONLINE IT GURU said...

Advance your career with salesforce admin certification classes designed to build real-world Salesforce expertise.

ONLINE IT GURU said...

Experienced professional specializing in salesforce developer classes building scalable Apex, Lightning, and integration solutions.