如何在TypeScript中打印字母?

时间:2017-10-22 07:33:33

标签: angular typescript

我们正在尝试使用Angular设计一个医疗保健应用。对于数据过滤,我们正在创建一个如下图所示的栏:

Data Filterbar image

为了减少我们在Typescript中编写代码的代码行,我们在控制台中检查它是否显示。

我们没有得到预期的输出,也没有显示错误。

任何人都可以解决此问题吗?

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

输出:

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

供您参考我发布完整的TS文件:

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;    }

}

1 个答案:

答案 0 :(得分:3)

希望这会有所帮助......

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