繁体   English   中英

咕causing声导致错误TS1005:';' 预期

[英]grunt causing error TS1005: ';' expected

我正在使用angular和Typescript访问REST Web服务。 我对打字稿很陌生,所以我的问题可能很基本,或者我的方法是错误的。 我一直收到错误TS1005: ';' expected 当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(...) {...} 
}

错误出现在$scope.submit所在的行。 任何建议都适用。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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