我想循环播放一个数组。
有我的代码:
@Input()
applicationLinks: ApplicationLink[];
applicationRows: ApplicationLinkRow[];
for(applicationLink in applicationLinks) {
applicationRows.push(applicationLink);
}
in给出编译错误
(=预期)。
我也试过
for(applicationLink of applicationLinks)
for(var applicationLink in applicationLinks)
for(var applicationLink of applicationLinks)
每次都会出现编译错误!
答案 0 :(得分:3)
您需要将此代码移动到方法或构造函数
中for(applicationLink in applicationLinks) {
applicationRows.push(applicationLink);
}
应该是这样的:
class SomeClass {
@Input()
applicationLinks: ApplicationLink[];
applicationRows: ApplicationLinkRow[];
someMethod() {
for(applicationLink in applicationLinks) {
applicationRows.push(applicationLink);
}
}
}