0

オブジェクトを作成する必要があります。クラスとそのプロパティ、およびオブジェクトの作成は異なるファイルで行われます。

これはクラスを含むファイルです

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 が未定義のオブジェクトとして表示される側にあります。初期化されていません。このことに1つのファイルを使用すると(2つのファイルはありません)、うまく機能します。その方法と理由を知っている人はいますか?

4

1 に答える 1

1

2 つの typescript ファイルを 1 つの javascript ファイルにマージする場合は、 --out コンパイラ フラグを指定する必要があります。

それ以外の場合、各 typescript ファイルは個別の javascript ファイルにコンパイルされ、正しい順序でそれらをロードする責任があります。

于 2013-08-19T12:48:54.773 に答える