Doubt with AngularJS

0

What's wrong with this code? I'm trying to run it, but in no way does it show me the data coming from the bank!

var app = angular.module('app', []);

app.controller('clienteController', ['$scope', '$http', clienteController]);

function clienteController($scope, $http) {
  $http.get('http://localhost:3091/api/ClientesWebAPI/Getcliente')
    .success(function (data) {
      $scope.listaclientes = data;

    })
    .error(function () {
      $scope.erro = "Erro: Nao foi possivel carregar.";
    });
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



<h2>Listagem de Clientes</h2>

<div data-ng-controller="clienteController">
    <div class="panel panel-default">
        <div class="panel-heading">Lista de clientes</div>
        <div class="panel-body">


    <div class="row">
                <div class="col-md-12">
                    <strong>{{erro}}</strong>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <tr>
                                <td>ID</td>
                                <td>Nome</td>
                                <td>Email</td>
                                <td>Idade</td>
                                <td>Data nascimento</td>
                                <td>Data cadastro</td>
                            </tr>
                            <tr ng-repeat="cliente in listaclientes">
                                <td>{{ cliente.id_nome }}</td>
                                <td>{{ cliente.nome }}</td>
                                <td>{{ cliente.idade }}</td>
                                <td>{{ cliente.sexo }}</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    
    
asked by anonymous 14.03.2017 / 19:48

1 answer

0

You're missing the ng-app="app" for the angular start and render on your page.

Where is <div data-ng-controller="clienteController">

Must stay      <div ng-app="app" data-ng-controller="clienteController">

Do not forget to check if you've placed references to AngularJS files on your page.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Below is an example that works:

var app = angular.module('app', []);

app.controller('clienteController', ['$scope', '$http', clienteController]);

function clienteController($scope, $http) {
  $http.get('http://localhost:3091/api/ClientesWebAPI/Getcliente')
    .success(function (data) {
      $scope.listaclientes = data;

    })
    .error(function () {
      $scope.erro = "Erro: Nao foi possivel carregar.";
    });
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



<h2>Listagem de Clientes</h2>

<div ng-app="app" data-ng-controller="clienteController">
    <div class="panel panel-default">
        <div class="panel-heading">Lista de clientes</div>
        <div class="panel-body">


    <div class="row">
                <div class="col-md-12">
                    <strong>{{erro}}</strong>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <tr>
                                <td>ID</td>
                                <td>Nome</td>
                                <td>Email</td>
                                <td>Idade</td>
                                <td>Data nascimento</td>
                                <td>Data cadastro</td>
                            </tr>
                            <tr ng-repeat="cliente in listaclientes">
                                <td>{{ cliente.id_nome }}</td>
                                <td>{{ cliente.nome }}</td>
                                <td>{{ cliente.idade }}</td>
                                <td>{{ cliente.sexo }}</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    
14.03.2017 / 20:33