咕噜声导致错误TS1005:&#39 ;;'预期

时间:2015-04-13 08:26:49

标签: angularjs gruntjs typescript

我正在使用angular和typescript来访问REST webservice。我对打字稿很新,所以我的问题可能很基本,或者我的方法是错误的。当grunt编译我的exampleController.ts时,我一直收到错误TS1005: ';' expected。 我已经搜索了解决方案,但我找不到任何可以帮助我的方法。我已经在使用import angular = require('angular');了 我的控制器代码看起来像这样:

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(...) {...} 
}
<{1}}所在的行显示

错误。任何建议都是适当的。

1 个答案:

答案 0 :(得分:1)

代码$scope.submit...必须位于构造函数中。构造函数的参数必须与$inject列表匹配:

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) {
        });
    };
  }
}
相关问题