从Angularjs中的数组中获取特定元素

我有一个数组,我想使用指令从数组中获取特定元素(例如array [0]),但我不知道如何实现。我意识到这是angularjs的基础,但是我找不到任何解决方案。请帮忙:)

这是数组

    $scope.array = [
      {
        text: '1',},{
        text: '2',{
        text: '3',}]

然后在视图中使用该构造

<div ng-repeat="element in array">
     <content></content>
</div>

这就是包含该指令的内容

<p>{{array.text}}</p>
A19900919woaijisuanj 回答:从Angularjs中的数组中获取特定元素

在html中: 在内容指令中,您必须添加 bindToController:{data:“ =”}

,

您可以在指令中设置相同的var而不是data

<div ng-repeat="element in array">
     <content></content>
</div>

指令:

<p>{{element.text}}</p>

如果指令涉及customer数据,则应使用{{ customer.text }},如果是这种情况,则可以继续使用相同的作用域...

<div ng-repeat="customer in array">
     <content></content>
</div>

指令:

<p>{{customer.text}}</p>
本文链接:https://www.f2er.com/3159857.html

大家都在问