Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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 如何使用*ngFor仅显示数组中的一项?_Angular - Fatal编程技术网

Angular 如何使用*ngFor仅显示数组中的一项?

Angular 如何使用*ngFor仅显示数组中的一项?,angular,Angular,我在component.ts文件中创建了一个名为title的数组: this.projectInfo = { title: [ 'Title 1', 'Title 2', 'Title 3', 'Title 4', 'Title 5', 'Title 6', ], 对于模板中的每个“项目”,我只想使用该数组中的一个标题: <div class="item2

我在component.ts文件中创建了一个名为
title
的数组:

    this.projectInfo = {
      title: [
        'Title 1',
        'Title 2',
        'Title 3',
        'Title 4',
        'Title 5',
        'Title 6',
      ], 
对于模板中的每个“项目”,我只想使用该数组中的一个标题:

  <div class="item2">
    <img class="center" src="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/tnc_48980557.jpg?crop=961,0,1928,2571&wid=600&hei=800&scl=3.21375">
    <h5 *ngFor="let projectTitle of projectInfo.title">{{projectTitle}}</h5>
    <p>{{ projectInfo.description }}</p>
  </div>
  <div class="item2">
    <img class="center" src="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/tnc_48980557.jpg?crop=961,0,1928,2571&wid=600&hei=800&scl=3.21375">
    <h5 *ngFor="let projectTitle of projectInfo.title">{{projectTitle}}</h5>
    <p >{{ projectInfo.description }}</p>
  </div>
  <div class="item2">
    <img class="center" src="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/tnc_48980557.jpg?crop=961,0,1928,2571&wid=600&hei=800&scl=3.21375">
    <h5 *ngFor="let projectTitle of projectInfo.title">{{projectTitle}}</h5>
    <p>{{ projectInfo.description }}</p>
  </div>

{{projectTitle}}
{{projectInfo.description}}

{{projectTitle}} {{projectInfo.description}

{{projectTitle}} {{projectInfo.description}}

我想在第一个“项目”中使用“标题1”,在第二个“项目”中使用“标题2”,等等

我已经尝试使用
let I=index
来帮助指定要使用该数组中的哪个标题,但找不到如何使用

我对Angular还是个新手,所以任何帮助/指导都将不胜感激。谢谢

那么:

{{projectTitle[0]}}
?


将0替换为i

将其放在整个块上,然后重复该块

<div class="item2" *ngFor="let projectTitle of projectInfo.title">
  <img class="center" src="https://natureconservancy-h.assetsadobe.com/is/image/content/dam/tnc/nature/en/photos/tnc_48980557.jpg?crop=961,0,1928,2571&wid=600&hei=800&scl=3.21375">
  <h5>{{projectTitle}}</h5>
  <p>{{ projectInfo.description }}</p>
</div>

{{projectTitle}}
{{projectInfo.description}}


您正在使用angularJS或angularJS。编辑问题中的标签,以避免这种常见的混淆!