How to list parents and city in Anglican?

Asked

Viewed 598 times

1

Here’s what I wanna do:

Brazil Rio Grade do Sul Brazil Rio de Janeiro ... and so on.

It has how to do it in a table?

<table width="500" border="1">
    <tr>
        <td width="200" align="center">País</td>
        <td width="300" align="center">Estado</td>
    </tr>
    <tr>
        <td>{{pais}}</td>
        <td>{{estado}}</td>
    </tr>
</table>

Country and state are each in a table.

  • 1

    Please add more details to your question, including the code you already have, how you are getting the data and the expected result (if this is the problem).

  • I only have html, but not the controller to display the data.

  • But it was enough to understand how you wanted the return, I made an example for you in the reply.

2 answers

1

Complete example using your expected return.

You can run the code to test.

angular.module('myApp', [])
  .controller('EstadosController', function() {
    var estados = this;
    estados.lista = [{
      pais: 'Brasil',
      estado: 'Rio Grande do Sul'
    }, {
      pais: 'Brasil',
      estado: 'Santa Catarina'
    }];
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="EstadosController as estados">
    <ul class="unstyled">
      <table width="500" border="1">
        <tr>
          <td width="200" align="center">País</td>
          <td width="300" align="center">Estado</td>
        </tr>
        <tr ng-repeat="estado in estados.lista">
          <td>{{estado.pais}}</td>
          <td>{{estado.estado}}</td>
        </tr>
      </table>
    </ul>
  </div>
</div>

If you solve your problem, please accept the answer and vote in favour.

0

There is, and it’s very simple. Just do this:

<tr ng-repeat="dados in meuScope">
    <td>{{dados.pais}}</td>
    <td>{{dados.estado}}</td>
</tr>

Where meuScope is the value of $scope defined in controller.

Example:

$scope.meuScope = [
    {pais: 'Brasil', estado: 'Rio de Janeiro'},
    {pais: 'Brasil', estado: 'São Paulo'},
    //etc...
];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.