Javascript ';推动';在我的构造函数中未定义的

Javascript ';推动';在我的构造函数中未定义的,javascript,typescript,angular7,Javascript,Typescript,Angular7,还在学习。在尝试填充构造函数中的数字数组时看到了这一点 错误:未捕获(承诺中):TypeError:无法读取未定义的属性“push” 尝试像这样在我的构造函数中填充数组 导出类注册表组件实现OnInit{ @Output()cancelRegister=neweventemitter(); 用户:用户; registerForm:FormGroup; bsConfig:部分; emailErrorMessage:字符串; userErrorMessage:字符串; 当前年份:编号=新日期().

还在学习。在尝试填充构造函数中的数字数组时看到了这一点

错误:未捕获(承诺中):TypeError:无法读取未定义的属性“push”

尝试像这样在我的构造函数中填充数组

导出类注册表组件实现OnInit{
@Output()cancelRegister=neweventemitter();
用户:用户;
registerForm:FormGroup;
bsConfig:部分;
emailErrorMessage:字符串;
userErrorMessage:字符串;
当前年份:编号=新日期().getFullYear();
startYear=this.currentYear-120;
年份:数字[];
构造函数(专用authService:authService,专用路由器:路由器,
私有alertify:AlertifyService,私有fb:FormBuilder){
for(设i=this.currentYear;i>this.startYear;i--){
这。年。推(一);
}

}
必须初始化类的属性

export class RegisterComponent implements OnInit {
 ...
 years: number[] = [];
 ...

必须初始化类的属性

export class RegisterComponent implements OnInit {
 ...
 years: number[] = [];
 ...

我的错!我假设第一组括号是init。谢谢!我的错!我假设第一组括号是init。谢谢!