最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS script gives error ReferenceError Invalid left-hand side in assignment - Stack Overflow

programmeradmin2浏览0评论

In my path to make connection with a webservice, I tried to manage it this with AngularJS $http option. But when I try to test it, I get the next error in my chrome console: ReferenceError Invalid left-hand side in assignment. I checked the code three times but I cannot figure out what I am doing wrong. This is my testscript:

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

I used the "Add Some Control" example on www.angularjs for my test script. My webservice is equal to the tutorial of ServiceStack: .Hello/

My question is, what causes the error I am getting in the angular.min.js file?

In my path to make connection with a webservice, I tried to manage it this with AngularJS $http option. But when I try to test it, I get the next error in my chrome console: ReferenceError Invalid left-hand side in assignment. I checked the code three times but I cannot figure out what I am doing wrong. This is my testscript:

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

I used the "Add Some Control" example on www.angularjs for my test script. My webservice is equal to the tutorial of ServiceStack: http://www.servicestack/ServiceStack.Hello/

My question is, what causes the error I am getting in the angular.min.js file?

Share Improve this question asked Jun 11, 2013 at 10:10 CornelisCornelis 1,8396 gold badges29 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Seems like this is problematic :

$scope.testService() = function() {

may be you should try to change it like this:

$scope.testService = function() {

Change $scope.testService() to $scope.testService

发布评论

评论列表(0)

  1. 暂无评论