没有调用打字稿模型方法

时间:2017-04-10 15:48:21

标签: angular typescript

有人能帮帮我吗? 我有一个打字稿模型,我想使用该模型中的方法,但当我做{{myvar.ContractNumber.GetCompanyContractNumber()}}时,我什么都没有。我的方法没有被调用。这是模型:

export class ContractNumber {
    constructor() {
        this.Prefixes = new Array<string>();
        this.Suffixes = new Array<string>();
    }

    public Prefixes: string[];
    public CompanyNumber: string;
    public Number: string;
    public Suffixes: string[];

    public Init(): void {
        this.Prefixes = new Array<string>();
        this.Suffixes = new Array<string>();
    }

    public DisplayPrefix(separator: string = ""): string {
        var str = "";
        var max = this.Prefixes.length;
        for (var index = 0; index < max; index++) {
            if (index + 1 == max)
                str += this.Prefixes[index];
            else
                str += this.Prefixes[index] + separator;
        }
        return str;
    }

    public DisplaySuffix(separator: string = ""): string 
    {
        var str = "";
        var max = this.Suffixes.length;
        for (var index = 0; index < max; index++) {
            if (index + 1 == max)
                str += this.Suffixes[index];
            else
                str += this.Suffixes[index] + separator;
        }
        return str;
    }

    public GetContractNumber(): string 
    {
        return this.DisplayPrefix() + Number + this.DisplaySuffix();
    }

    public GetCompanyContractNumber(): string {
        var str = "";
        for (var index = 0; index < this.Prefixes.length; index++) {
            str += this.Prefixes[index];
        }
        str += this.CompanyNumber != null
            ? this.CompanyNumber
            : this.Number;

        for (var index = 0; index < this.Suffixes.length; index++) {
            str += this.Suffixes[index];
        }
        return str;
    }
    public cn = () => {
        var str = "";
        for (var index = 0; index < this.Prefixes.length; index++) {
            str += this.Prefixes[index];
        }
        str += this.CompanyNumber != null
            ? this.CompanyNumber
            : this.Number;

        for (var index = 0; index < this.Suffixes.length; index++) {
            str += this.Suffixes[index];
        }
        return str;
    } 
}

谢谢。

0 个答案:

没有答案