Request the API using angularjs

1

I'm still new to development using AngularJs and I'm having trouble accessing an API:

.controller('RegulamentoCtrl', function($scope, $state, $http, $ionicPopup, AuthService) {

    $http.get('http://rest-service.guides.spring.io/greeting')
    .then(function(response) {
        alert('teste');
    }, function(err) {
        alert(err)
    });
})

When trying to access this service, which returns me a JSON, I get the following error message:

  

Error: Unexpected request: GET    link No more request expected

    
asked by anonymous 06.10.2016 / 22:22

1 answer

3

In the end I discovered the problems! :)

The problem is that I'm using ngMockE2E to process requests locally (for access control).

angular.module('starter', ['ionic', 'ngMockE2E'])

So my API request was not passed to the server. To solve the problem I just had to tell ngMockE2E to pass my request to the server:

.run(function($httpBackend){

  ...

  $httpBackend.whenGET('http://rest-service.guides.spring.io/greeting').passThrough();

 // configuração básica mock
  $httpBackend.whenGET(/templates\/\w+.*/).passThrough();
 })

Response font: link

    
07.10.2016 / 00:16