quicky
quicky

Reputation: 97

grunt causing error TS1005: ';' expected

I'm using angular and typescript to access REST webservice. I'm quite new to typescript so my problem is maybe pretty basic or my approach is wrong. I keep getting en error TS1005: ';' expected when grunt compiles my exampleController.ts. I searched for the the solution already but I haven't found anything that would help me. I'm already using import angular = require('angular'); My controller code looks some like this:

class ExampleComponentController {

public static $inject = [
  '$scope',
  'productRestService',
  '$http'
];

$scope.submit = function(form) {

    var config = {
        'username' : $scope.name,
        'password' : $scope.pass
    };

    var $promise = $http.post('requat_url', config)
        .success(function(data, status, headers, config) {
            ...
        })
        .error(function(data, status, headers, config) {
            ...
        });
}; 

constructor(...) {...} 
}

error appears on the line where $scope.submit is. Any advise is appriciated.

Upvotes: 0

Views: 398

Answers (1)

Paleo
Paleo

Reputation: 23702

The code $scope.submit... must be in the constructor. The parameters of the constructor must match to the $inject list:

class ExampleComponentController {
  public static $inject = [
    '$scope',
    'productRestService',
    '$http'
  ];

  constructor($scope, productRestService, $http) {
    $scope.submit = function (form) {

      var config = {
        'username': $scope.name,
        'password': $scope.pass
      };

      var $promise = $http.post('requat_url', config)
        .success(function (data, status, headers, config) {
        })
        .error(function (data, status, headers, config) {
        });
    };
  }
}

Upvotes: 1

Related Questions