简体   繁体   中英

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

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) {
        });
    };
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM