【问题标题】:grunt causing error TS1005: ';' expected咕噜声导致错误 TS1005:';'预期的
【发布时间】:2015-04-13 08:26:48
【问题描述】:

我正在使用 Angular 和 typescript 来访问 REST Web 服务。我对打字稿很陌生,所以我的问题可能很基本,或者我的方法是错误的。当 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 所在的行。任何建议都会被采纳。

【问题讨论】:

    标签: angularjs gruntjs typescript


    【解决方案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) {
            });
        };
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-07
      • 2014-07-25
      • 1970-01-01
      • 2012-12-05
      • 2016-01-10
      • 2018-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多