Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.org for my test script. My webservice is equal to the tutorial of ServiceStack: http://www.servicestack.net/ServiceStack.Hello/

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

like image 975
Cornelis Avatar asked Feb 16 '23 06:02

Cornelis


2 Answers

Seems like this is problematic :

$scope.testService() = function() {

may be you should try to change it like this:

$scope.testService = function() {
like image 122
Ivan Chernykh Avatar answered Apr 26 '23 11:04

Ivan Chernykh


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

like image 28
holographic-principle Avatar answered Apr 26 '23 09:04

holographic-principle