【问题标题】:Display array as list in angular将数组显示为角度列表
【发布时间】:2015-03-18 21:01:33
【问题描述】:

我的 javascript 中有一个名为“animals”的数组:

var animals = ["dog", "cat", "horse", "cow"];

我的html是:

<p>{{animals}}</p>

目前显示如下:

["dog", "cat", "horse", "cow"]

我希望它显示如下:

dog
cat
horse
cow

我已经查看了 ng-list 指令的官方 Angular 文档,但仍在摸不着头脑。可能有另一个(更好的)指令吗?

不胜感激。

【问题讨论】:

    标签: arrays angularjs string angular-nglist


    【解决方案1】:

    使用 ng-repeat:

    <p ng-repeat="animal in animals">{{animal}}</p>
    

    或

    <ul>
        <li ng-repeat="animal in animals">{{animal}}</li>
    </ul>
    

    【讨论】:

    • 谢谢;比我打算做的要简单得多。现在可以使用了。
    • 很高兴能提供帮助。如果它解决了您的问题,您可以将其标记为答案吗?
    猜你喜欢
    • 2018-10-25
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 2020-08-24
    • 2019-12-31
    • 2014-11-08
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多