簡體   English   中英

在typeScript上未定義類

[英]Class is undefined on typeScript

我需要創建一個對象。 類及其屬性和對象創建在不同的文件上進行。

這是包含類的文件

module Model {

export class DonationServiceResponse {
    ErrorMessage: string;
    ErrorCode: number;
    Comapny: string;
    StreateName: string;
    IsAnonymous: boolean;
    IsOneOffDonation: boolean;
    DonationIntentType: number;
    EmployeeId: number;
    Amount: number;
    LogoImage: string;
    Id: number;
}}

在下面的文件對象創建發生

  /// <reference path="DonationServiceResponse.ts" />
/// <reference path="../../typings/angularjs/angular.d.ts" />

angular.module('myApp', []);

interface IDonationServiceController {
    Tiles: Array;
    TileContainerEntities: Array;
    TotalAmount: number;
}


class TileContainerEntity  {

    DonationContainer: test.DonationServiceResponse;
    httpService: any;
    scope: any;
    res: boolean;
    AnonymousText: string;
    OneTimeText: string;

    constructor(donationAmount: number, charityLogo: string, anonymous: bool, oneTime: bool, id: number, employeeId: number, http: ng.IHttpService, scope: ng.IHttpService) {

        this.DonationContainer = new test.DonationServiceResponse();
        this.DonationContainer.Amount = donationAmount;
        this.DonationContainer.LogoImage = charityLogo;
        this.DonationContainer.Id = id;
        this.DonationContainer.EmployeeId = employeeId;
        this.httpService = http;
        this.scope = scope;
    }

}

class DonationServiceController implements IDonationServiceController {
    private httpService: any;
    TotalAmount: number = 0;
    Tiles: TileContainerEntity[];
    TileContainerEntities: TileContainerEntity[];

    constructor($scope, $http: ng.IHttpService) {
        this.httpService = $http;
        $scope.VM = this;
        this.getAllTiles($scope.VM, $http);
    }

    getAllTiles(scope, http): void {
        this.httpService.get("/API/PrivateAPI/test").success(function (data, status) {
            this.TileContainerEntities = [];

            var num = 0;

            for (var index = 0; index < data.length; index++) {
                var amount = data[index].Amount;
                var chairtyLogo = data[index].LogoImage;
                var isAnonymousOff = data[index].IsAnonymous;
                var isOneOff = data[index].IsOneOffDonation;
                var id = data[index].Id;
                var empId = data[index].EmployeeId;
                var tileEntity = new TileContainerEntity(amount, chairtyLogo, isAnonymousOff, isOneOff, id, empId, http, scope);
                this.TileContainerEntities.push(tileEntity);
                num = num + data[index].Amount;
            }
            scope.Tiles = this.TileContainerEntities;
            scope.TotalAmount = num;

        });
    }
}

我的問題是在構造函數DonationContainer顯示為未定義的對象。 它不是初始化的。 如果我為此事情使用一個文件(沒有兩個文件),它的效果很好。有人知道如何這樣做和原因嗎?

如果要將兩個打字稿文件合並為一個javascript文件,則需要指定--out編譯器標志。

否則,每個打字稿文件都將編譯成一個單獨的javascript文件,您有責任以正確的順序加載它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM