在Angular中,可以使用组件和指令来获取和重复显示两个主要块。下面是一个示例解决方法:
首先,在app.component.html文件中,定义两个主要块的模板:
Block 1
This is the first block.
Block 2
This is the second block.
接下来,在app.component.ts文件中,创建一个数组来存储要显示的块的引用:
import { Component, ViewChild } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild('block1') block1: any;
@ViewChild('block2') block2: any;
blocks: any[] = [];
constructor() {
// 添加两个块的引用到数组中
this.blocks.push(this.block1);
this.blocks.push(this.block2);
}
}
然后,在app.component.html文件中,使用ngFor指令来重复显示这些块:
通过上述代码,我们定义了两个主要块的模板,并将它们的引用存储在AppComponent的blocks数组中。然后,使用ngFor指令遍历blocks数组,并使用ngTemplateOutlet指令来重复显示每个块的内容。
这样,当Angular应用程序运行时,将会获取并重复显示这两个主要块。