0

我最近将我的项目从 angular6 升级到了 angular7。Visual Studio 代码开始在推送、长度等方面显示警告。例如, [ts] 属性“推送”在类型“{}”上不存在。

我已经初始化了数组

this.errorMessages = [];
this.errorMessages.push(errorMessage);

同样,它的长度也显示

if(this.model.str.length > 0)

[ts] 类型“字符串”上不存在属性“长度”。

但是当它运行时

服务

它运行正常。有什么建议么

4

1 回答 1

0

正确的。

export class SignInComponent implements OnInit {
  // Define the calss property
  // If we don't want to access class property outside the class then we need to define private
  // private errorMessages = [];
  errorMessages = [];

  constructor() { }

  ngOnInit() {
    this.errorMessages.push(this.errorMessages);
    console.log(this.errorMessages.length);
    // Output 1
  }
}
于 2019-02-08T07:30:20.930 回答