最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use foreach with AngularJS on HTML - Stack Overflow

programmeradmin0浏览0评论

How do I use a foreach statment in angular js? My current data is printing out as a json format. I want to make it printed out on new lines.

Html

<p>{{controller.greeting.custinfo}}</p>

 //attempt
<p ng-repeat= >{{controller.greeting.custinfo}}</p>

Output on UI

{"id":null,"biling_address":"null","billing_state":"FL","ip_Addresses":["123:111:2101","","NULL"],name":"jimmmy"}

java output

System.out.println(custinfo);
demo.model.cert@ba1983a

How can I use a foreach statement to display the data in new lines? Rather than a json format.

I know how to do this with thymeleaf,example below

<table th:each="custinfo : ${custinfo}">

  <tr>
        <td ng-show="id" class="padded">id:</td>
        <td ng-show="id" th:text="${custinfo.id}" class="padded"></td>
  </tr>
  //continue down

How do I use a foreach statment in angular js? My current data is printing out as a json format. I want to make it printed out on new lines.

Html

<p>{{controller.greeting.custinfo}}</p>

 //attempt
<p ng-repeat= >{{controller.greeting.custinfo}}</p>

Output on UI

{"id":null,"biling_address":"null","billing_state":"FL","ip_Addresses":["123:111:2101","","NULL"],name":"jimmmy"}

java output

System.out.println(custinfo);
demo.model.cert@ba1983a

How can I use a foreach statement to display the data in new lines? Rather than a json format.

I know how to do this with thymeleaf,example below

<table th:each="custinfo : ${custinfo}">

  <tr>
        <td ng-show="id" class="padded">id:</td>
        <td ng-show="id" th:text="${custinfo.id}" class="padded"></td>
  </tr>
  //continue down
Share Improve this question edited Mar 12, 2019 at 9:49 lin 18.4k4 gold badges65 silver badges87 bronze badges asked Apr 12, 2017 at 16:06 Mike.ChunMike.Chun 3783 gold badges11 silver badges29 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 7

Just loop thru it:

 <p ng-repeat="(key, value) in controller.greeting.custinfo">{{key}}: {{value}}</p>

To display a list using AngularJS, you need an array that you will iterate.

Let's say you have list of customers

$scope.customers = [{id:1, name:'customer1'}, .....];

You will do so this

 <ul>
<li ng-repeat="custInfo in customers">{{custInfo.name}}       </li>
</ul>

AngularJS can iterate over object with ng-repeat.

$scope.data = {"id":null,"biling_address":"null","billing_state":"FL","ip_Addresses":["123:111:2101","","NULL"],"name":"jimmmy"};

<table>
  <tr ng-repeat="(key, value) in data">
    <td>{{key}}</td>
    <td class="padded">{{value}}</td>
  </tr>
</table>

Example for your data: https://jsfiddle.net/fn8rqjz2/1/

If you want to show or hide elements based on id:

<tr ng-show="data.id" ng-repeat="(key, value) in data">

Try this:

<p ng-repeat="(key, value) in yourObj">{{yourObj[key]}}</p>

If I understood what are you trying to do.

发布评论

评论列表(0)

  1. 暂无评论