【发布时间】:2018-04-20 02:06:53
【问题描述】:
即使 Visual Studio 代码没有给我任何错误,我也以某种方式在 chrome 的控制台中收到了该错误。
这是我在 interfaces.ts 中的代码
export interface Data1{
month: string;
employeeName: string;
date: string;
employmentStatus: string[];
}
这是我在 tables.component.ts 中的代码
import { Component, OnInit } from '@angular/core';
import { Data1 } from '../../../shared/interfaces';
@Component({
selector: 'app-tables',
templateUrl: './tables.component.html',
styleUrls: ['./tables.component.css']
})
export class TablesComponent implements OnInit {
today = new Date();
dataForTable1: Data1;
months: string[] = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
constructor() {
console.log(this.today.getMonth());
console.log(this.months[this.today.getMonth()]);
this.dataForTable1.month = this.months[this.today.getMonth()]
this.dataForTable1.employeeName = '';
this.dataForTable1.date = this.today.getDate().toLocaleString();
this.dataForTable1.employmentStatus = [''];
}
ngOnInit() {
}
}
我尝试使用 console.log 进行调试,但它给了我正确的输出,但我不知道为什么它说未定义。 我目前正在使用 Angular CLI:1.7.4;节点:8.11.1;打字稿:2.8.1 希望有人可以提供帮助。
【问题讨论】:
-
您没有从 Typescript 收到编译时错误的原因是该错误是运行时错误(类似于 C# 中的对象引用错误)。
标签: javascript angular typescript