1

私は AngularJS から始めており、REST サービスを使用する必要があります。この GET 呼び出しが機能しないのはなぜですか?

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>
4

1 に答える 1

4

関数に $http を渡していません:

function GetController($scope)

に:

function GetController($scope, $http)

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

真剣に、コンソールを確認する必要があります。コンソールを開いていると、「ReferenceError: $http is not defined」のようなものが表示されます。

于 2014-03-14T16:17:50.240 に答える