4

在我与 web 服务建立连接的路径中,我尝试使用 AngularJS $http 选项来管理它。但是当我尝试测试它时,我的 chrome 控制台中出现下一个错误:ReferenceError Invalid left-hand side in assignment。我检查了三遍代码,但我无法弄清楚我做错了什么。这是我的测试脚本:

<!doctype html>
<html ng-app>
  <head>
    <title>Test webservice</title>
      <script type="text/javascript" src="./jquery-1.9.1.js"></script>
      <script type="text/javascript" src="./angular.min.js"></script>
      <script type="text/javascript" src="./angular-resource-min.js"></script>
      <script type="text/javascript">
        function testWebservice($scope, $http) {
          $scope.testService() = function() {
            $http.get("http://localhost:1325/hello/world")
              .success(function(data, status, headers, config) {
                alert(data);
              })
              .error(function(data, status, headers, config) {
                alert(status);
              });
          };
        }

      </script>
    <head>
  <body>
    <div ng-controller="testWebservice">
      <form ng-submit="testService()">
        <input type="submit" value="test">
      </form>
    </div>
  </body>
</html>

我使用 www.angularjs.org 上的“添加一些控件”示例作为我的测试脚本。我的webservice相当于ServiceStack的教程:http ://www.servicestack.net/ServiceStack.Hello/

我的问题是,是什么导致我在 angular.min.js 文件中出现错误?

4

2 回答 2

5

似乎这是有问题的:

$scope.testService() = function() {

可能您应该尝试像这样更改它:

$scope.testService = function() {
于 2013-06-11T10:14:46.633 回答
3

更改$scope.testService()$scope.testService

于 2013-06-11T10:15:11.777 回答