[英]Angular 8 Initialized Member Array is Undefined
Does anyone have any idea why the code below prints "undefined"?有谁知道为什么下面的代码打印“未定义”?
I have defined multiple objects and I want to display the pictures in what is to come, but I have noticed that when iterating with ngfor through them nothing was display so I decided to log this the array and the result was "undefined".我已经定义了多个对象,我想在接下来的内容中显示图片,但是我注意到当使用 ngfor 遍历它们时,没有显示任何内容,所以我决定记录这个数组,结果是“未定义”。
export class OwnedPlacesComponent implements OnInit {
items: [
{x: 30, y: 40, image: "https://imgur.com/U36N3uE"},
{x: 20, y: 88, image: "https://imgur.com/U36N3uE"},
{x: 50, y: 35, image: "https://imgur.com/U36N3uE"},
{x: 88, y: 55, image: "https://imgur.com/U36N3uE"},
];
constructor(
private authenticationService: AuthenticationService,
) {
}
ngOnInit() {
console.log(this.items);
}
} }
you are not initializing it你没有初始化它
items= [
{x: 30, y: 40, image: "https://imgur.com/U26N3uE"},
{x: 20, y: 88, image: "https://imgur.com/U26N3uE"},
{x: 50, y: 35, image: "https://imgur.com/U26N3uE"},
{x: 88, y: 55, image: "https://imgur.com/U26N3uE"},
];
use =
instead of :
使用
=
而不是:
There is a typo error, Initialise items with array of data instead of assigning the array of data as a type.有一个拼写错误,用数据数组初始化项目而不是将数据数组分配为类型。
Change from更改自
items: [
{x: 30, y: 40, image: "https://imgur.com/U26N3uE"},
{x: 20, y: 88, image: "https://imgur.com/U26N3uE"},
{x: 50, y: 35, image: "https://imgur.com/U26N3uE"},
{x: 88, y: 55, image: "https://imgur.com/U26N3uE"},
];
to到
items = [
{x: 30, y: 40, image: "https://imgur.com/U26N3uE"},
{x: 20, y: 88, image: "https://imgur.com/U26N3uE"},
{x: 50, y: 35, image: "https://imgur.com/U26N3uE"},
{x: 88, y: 55, image: "https://imgur.com/U26N3uE"},
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.