Pergunta

I'm starting with AngularJS and I need to consume a REST service with it. Why this GET call doesn't work?

controller.js

angular.module("myApp", []);

function GetController($scope) {

    $scope.click = function() {

        // $http.defaults.useXDomain = true;

        var response = $http.get('http://localhost:8080/ticketsales/pruebas');

        response.success(function(data, status, headers, config) {

            alert("Ok.");

        });

        response.error(function(data, status, headers, config) {
            alert("Error.");
        });

    };

}

index.html

<div ng-controller="GetController">

        <button ng-click="click()">Click me</button>

</div>
Foi útil?

Solução

You aren't passing $http to the function:

function GetController($scope)

to:

function GetController($scope, $http)

http://jsfiddle.net/rd13/mM2g7/2/

Seriously though, you need to look at your console, if you had a console open you would have seen something like: "ReferenceError: $http is not defined".

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top