Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如果只触发一次,则为ng_Angular_Typescript_Multidimensional Array - Fatal编程技术网

Angular 如果只触发一次,则为ng

Angular 如果只触发一次,则为ng,angular,typescript,multidimensional-array,Angular,Typescript,Multidimensional Array,今天我在一个angular应用程序上遇到了一个奇怪的行为 我们在nginit上的组件ts中填充了一个数组 for(let i = 0; i < 1; i++) { this.cluster[i] = []; for(let j = 0; j < 3; j++) { this.cluster[i][j] = false; } } for(设i=0;i

今天我在一个angular应用程序上遇到了一个奇怪的行为

我们在nginit上的组件ts中填充了一个数组

for(let i = 0; i < 1; i++) {
    this.cluster[i] = [];
    for(let j = 0; j < 3; j++) {
       this.cluster[i][j] = false;
    }
}
for(设i=0;i<1;i++){
这个.cluster[i]=[];
for(设j=0;j<3;j++){
this.cluster[i][j]=假;
}
}
component.html中,我们使用for循环迭代数组

<div *ngFor="let col of cluster; let iCol = index" class="col-sm-4 offset-sm-2 col-md-4 offset-md-0">
    <div *ngFor="let row of col; let iRow = index">
       <div*ngIf="(cluster.length < 2 && cluster[0].length < 4)">
            <p>Test</p>
       </div>
    </div>
</div>

试验

如果我没有完全错的话,我们应该得到3份打印的
“Test”
,但我们只得到1份


有人能告诉我错误出现在哪里吗。提前谢谢

您忘记关闭双引号

使用此html代码


试验


您忘记关闭双引号

使用此html代码


试验


在第二行中,集群阵列仅为一维空阵列。在你的第四行,你把它变成二维,然后用假的填充它?数组的用途是什么?@ochs.tobi i创建一个网格(例如3x3),可以用true填充。有点像零和叉。但是您上面定义的数组只有1x3,因为第一个for循环只执行一次。@ochs.tobi暂时为true,但是当应用程序与用户一起运行时,if将被更多行填充Interaction@sHamann删除
*ngIf
时会发生什么情况。我还可以看到结尾处缺少双引号,但我想这只是问题中的一个输入错误。在你的第二行中,集群数组只是一维空数组。在你的第四行,你把它变成二维,然后用假的填充它?数组的用途是什么?@ochs.tobi i创建一个网格(例如3x3),可以用true填充。有点像零和叉。但是您上面定义的数组只有1x3,因为第一个for循环只执行一次。@ochs.tobi暂时为true,但是当应用程序与用户一起运行时,if将被更多行填充Interaction@sHamann删除
*ngIf
时会发生什么情况。我还可以看到结尾处缺少了一个双引号,但我想这只是创造性问题中的一个拼写错误,只是我的一个拼写错误。很遗憾,这只是我的一个打字错误。Sry
<div *ngFor="let col of cluster; let iCol = index" class="col-sm-4 offset-sm-2 col-md-4 offset-md-0">
    <div *ngFor="let row of col; let iRow = index">
       <div *ngIf="(cluster.length < 2 && cluster[0].length < 4)">
            <p>Test</p>
       </div>
    </div>
</div>