How to call a service in C # using AngularJS

0

Good afternoon, so I'm in doubt on how to call a service in C #, I've tried in many ways but I did not succeed.

(function () {
    'use strict';

    function Service($http, $q) {
        const url = 'http://172.23.1.31:81/Service1.svc';

        const servico = {
            obterTodos: obterTodos,
            excluir: excluir,
            obter: obter,
            criar: criar,
            alterar: alterar
        };

        //Obter nomes banco de dados

        function obterTodos() {
            const promise = $http.get(url);
            return promise.then(aoRequisicaoConcluir, aoRequisicaoFalhar);
        }

        //obter um apelido específico:

        function obter(id) {
            const urlComId = url + '/' + id;
            const promise = $http.get(urlComId);
            return promise.then(aoRequisicaoConcluir, aoRequisicaoFalhar);
        }

        //Excluir apelido

        function excluir(id) {
            const urlComId = url + '/' + id;
            const promise = $http.delete(urlComId);
            return promise.then(aoRequisicaoConcluir, aoRequisicaoFalhar);
        }

        //Criar apelido novo

        function criar(TesteSafra) {
            const promise = $http.post(url, TesteSafra);
            return promise.then(aoRequisicaoConcluir, aoRequisicaoFalhar);
        }

        //Alterar um apelido:

        function alterar(TesteSafra) {
            const urlComId = url + '/' + TesteSafra.id
            const promise = $http.put(urlComId, TesteSafra);
            return promise.then(aoRequisicaoConcluir, aoRequisicaoFalhar);
        }

        //promise

        function aoRequisicaoConcluir(response) {
            return response.data;
        }

        function aoRequisicaoFalhar(response) {
            return $q.reject(response.statusText);
        }

        return servico;
    }

    safraService.$inject = ['$http', '$q'];

    angular.module('app')
        .factory('Service', Service);
})();
    
asked by anonymous 30.01.2018 / 19:36

1 answer

0

Probably the injection of $ http and $ q, the name of the service where it is being injected is different from the name of the one used. Being the function like Service and the injection in safraService .

(function () {
'use strict';

-->   function Service($http, $q) {
        ...
       }

-->   safraService.$inject = ['$http', '$q'];

angular.module('app')
    .factory('Service', Service); <--
})();
    
02.02.2018 / 20:04