Urstruely Ananth
Urstruely Ananth

Reputation: 83

How to print the alphabet in TypeScript?

We are trying to design a health care app using Angular. For data filtering we are creating a bar which looks like this below image:

Data Filterbar image

To reduce the line of code we are writing the code in Typescript we are checking in the console whether its displaying or not.

We are not getting the expected output nor is it showing errors.

Can anyone fix this issue?

listIndex(){
while (this.i <= 90) {
    this.alphabets.push(String.fromCharCode(this.i));
}
console.log(this.alphabets());}

Output:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

For your reference I'm posting the full TS file:

import {Component} from '@angular/core';
import {HttpService} from '../../service/http.service';


@Component({
    selector: 'patienthtml',
    templateUrl: 'app/component/patient/patient.html',
    providers: [HttpService]
})

export class PatientComponent{
constructor( private httpService: HttpService ) {
}
 //simple call init function on controller
i=65;
step = 0;

patientData : any;
alphabets: any = [];

public ngOnInit(): any
{
    this.getPatientData();
}
 getPatientData(){

    this.httpService.getPatients("PatientData").subscribe(
    resp => {    
        if(resp!=null){

            this.patientData=resp.response;
        }
        console.log(this.patientData);
    },
    error => {
        console.log(error);
    }
    );   
}
listIndex(){
    console.log('ReachedHere');
    let alphabets = [];
    for (let i = 65; i <= 90;i++) {
        alphabets.push(String.fromCharCode(this.i));
    }
    console.log(alphabets);

}
getCurrentStep() {
    return this.step;
}
goback(){
    this.step = this.step - 1;    }

toReport(){
    this.step = this.step + 1;    }

}

Upvotes: 5

Views: 34411

Answers (1)

Ritesh Nair
Ritesh Nair

Reputation: 3355

Hope this helps...

let alphabets = [];
for (let i = 65; i <= 90;i++) {
    alphabets.push(String.fromCharCode(i));
}
console.log(alphabets);

Upvotes: 9

Related Questions