Query with reading data from a web api using Angularjs

Asked

Viewed 85 times

0

I have a web api made in Asp.net, I have a script that reads this data, but I’m not sure how to do the other methods. I am posting the code of the script is html that at the moment is running only GET. Thank you

Doubt: There is a $Scope method. $getAll where I would like to send a parameter to the query, this is not working.

You can download the files here:

https://drive.google.com/folderview?id=0B-svO0-4L_-NZF9pWFVwV3p4Wms&usp=sharing

(function () {
    'use strict';

    var numeros = angular.module("myModule", [])
    .controller("myController", function ($scope, $http, $log) {



        var sucessoCalBack = function (response) {
            $scope.detalhes = response.data;
        };

        var erroCalBack = function (response) {
            $scope.error = response.data;
        };


        //assim funciona, passando o parametro direto 
        $http({
            method: 'GET',
            params: { idusuario: 5 },
            url: 'http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi/consulta/JogosPorID/5'})
             .then(sucessoCalBack,erroCalBack);
        });


        $scope.$getAll = function (idusuario) {
            var config = {
                method: 'GET',
                url: 'http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi/consulta/JogosPorID/' + idusuario
            };
            $http(config).then(sucessoCalBack, erroCalBack);
        };



})();
<!DOCTYPE html>
<html ng-app="myModule">
<head>
    <meta charset="utf-8" />
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8">
    <!-- Bootstrap-->
    <link href="Content/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="Content/bootstrap.min.css" rel="stylesheet" media="screen" />
    <link href="Content/style.css" rel="stylesheet" media="screen" />
    <script src="Scripts/angular.min.js"></script>
    <script src="Scripts/Script.js"></script>


</head>


<body ng-controller="myController">

            <div class="container">
                <br><br>

                <table class="table table-striped table-bordered table-hover table-condensed">
                    <thead>
                        <tr>
                            <th>idjogodetalhe</th>
                            <th>nJogo</th>
                            <th>valor</th>
                            <th>total</th>
                            <th>idusuario</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="success" ng-repeat="detalhe in detalhes" >
                            <td>{{detalhe.idjogodetalhe}}</td>
                            <td>{{detalhe.nJogo}}</td>
                            <td>{{detalhe.valor}}</td>
                            <td>{{detalhe.total}}</td>
                            <td>{{detalhe.idusuario}}</td>

                        </tr>
                    </tbody>
                </table>
            </div>

         <button class="btn btn-primary  " data-ng-click="getAll(5)" >Listar Dados</button>    
         <button class="btn btn-primary  " ng-click="post(1245,20.10,20.10,4)" >Adicionar</button>     



            <!--javascript-->
            <script src="http://code.jquery.com/jquery.js"></script>
            <script src="Script/bootstrap.min.js"></script>
</body>
</html>
  • What exactly is your question? What is your expected behavior? What are the other methods you are struggling with?

  • There is a $Cope method. $getAll where I would like to send a parameter to the query, this is not working, I believe that if one works the other methods will also work following the same logic.

  • 1

    Can you display your method signature in Webapi? You are using Annotation [Route] to define the route of this method?

  • 1

    @Vinícius, I am using Route, you can view the data in the browser: 'http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi//JogosPorID/5

No answers

Browser other questions tagged

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