如何在ng-repeat中显示第一个数据?

时间:2022-11-25 16:37:50

How to display the first data in ng-repeat

如何在ng-repeat中显示第一个数据

<div class = "panel-body">
<div ng-repeat=" img in images">
    <img src="http://photo/{{img.path}}" alt="">
</div>
Panel content

example sql SELECT TOP 1 * FROM Customers;

示例sql SELECT TOP 1 * FROM Customers;

4 个解决方案

#1


2  

Use ng-if="$index == 0"

使用ng-if =“$ index == 0”

See below

见下文

<img ng-if="$index == 0" ng-src="http://photo/{{img.path}}" alt="" />

#2


2  

If you want to fetch only one record then use it like this. No need for ng-repeat.

如果您只想获取一条记录,那么就像这样使用它。不需要ng-repeat。

Or still if you want to use, then use $index.

或者如果你想使用,那么使用$ index。

<div class = "panel-body">
  <div ng-repeat=" img in images">
    <img src="http://photo/{{images[0].path}}" alt="">
 </div>

#3


1  

Use $first variable:

使用$ first变量:

<img ng-if="$first" ng-src="http://photo/{{img.path}}" alt="" />

如何在ng-repeat中显示第一个数据?

See https://docs.angularjs.org/api/ng/directive/ngRepeat

请参阅https://docs.angularjs.org/api/ng/directive/ngRepeat

#4


1  

If you want only the first data, you shouldn't need ngRepeat, just reference it by its index images[0]:

如果您只想要第一个数据,则不需要ngRepeat,只需通过索引图像[0]引用它:

<img ng-src="http://photo/{{images[0].path}}" alt="">

#1


2  

Use ng-if="$index == 0"

使用ng-if =“$ index == 0”

See below

见下文

<img ng-if="$index == 0" ng-src="http://photo/{{img.path}}" alt="" />

#2


2  

If you want to fetch only one record then use it like this. No need for ng-repeat.

如果您只想获取一条记录,那么就像这样使用它。不需要ng-repeat。

Or still if you want to use, then use $index.

或者如果你想使用,那么使用$ index。

<div class = "panel-body">
  <div ng-repeat=" img in images">
    <img src="http://photo/{{images[0].path}}" alt="">
 </div>

#3


1  

Use $first variable:

使用$ first变量:

<img ng-if="$first" ng-src="http://photo/{{img.path}}" alt="" />

如何在ng-repeat中显示第一个数据?

See https://docs.angularjs.org/api/ng/directive/ngRepeat

请参阅https://docs.angularjs.org/api/ng/directive/ngRepeat

#4


1  

If you want only the first data, you shouldn't need ngRepeat, just reference it by its index images[0]:

如果您只想要第一个数据,则不需要ngRepeat,只需通过索引图像[0]引用它:

<img ng-src="http://photo/{{images[0].path}}" alt="">