Angular+TypeScript:如何使用 HTTP Put 获取方法

Angular+TypeScript: How to get method using HTTP Put

我正在尝试使用 ANgularJs+TypeScript.I 在页面加载时获取我的所有下拉列表,我已完成实施 ng-optionsng-init 方法来加载它,但可能我遇到了一些问题,这就是为什么我无法从我的 API 获取我的数据或无法拨打我的 API.I 的原因已经为我的代码提供了这个问题。

这是我的打字稿控制器:-

/// <reference path="../interface/interface.ts" />
/// <reference path="../../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../../scripts/typings/angularjs/angular.d.ts" />

module CustomerNew.controllers {
    export class CreateCustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.create = this.create;
            $scope.getFormData = this.getformData;
        }
        public getformData: (getFormData: any) => {
            $http.get();
        }

给出错误AS 它给出了 "Property or signature expected" 错误和意外标记。 "A constructor, method, accessor, or property was expected"。

我们需要this.和“=”来分配getformData

 constructor(protected $scope: ICustomerScope,
        protected $http: ng.IHttpService,
        protected $templateCache: ng.ITemplateCacheService) {
        $scope.create = this.create;
        $scope.getFormData = this.getformData;
 }
 //public getformData: (getFormData: any) => {
 public getformData = (getFormData: any) => {
    // instead of this notation
    // $http.get(...
    // we need to use this.
    this.$http.get(...
 }

这可能是上述 TypeScript 控制器定义的一些更复杂的示例:

module CustomerNew.controllers
{
    export interface ICustomerScope extends ng.IScope
    {
        create: Function;
        getFormData: Function;
    }
    export class CreateCustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.create = this.create;
            $scope.getFormData = this.getformData;
        }
        public getformData = (getFormData: any) =>
        {
            this.$http.get("url"); // ...
        }
        public create = () => { }
    }
}

在这个typescript playgroundcompiler/transpiler

中查看