0

Can anyone help me please? I have a typescript model and i want to use a method which is in that model but when I do {{myvar.ContractNumber.GetCompanyContractNumber()}} I have nothing. My method is not called. Here is the model:

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;
    } 
}

Thank you.

7
  • Did you try myvar?.ContractNumber?.GetCompanyContractNumber() in your template. Commented Apr 10, 2017 at 15:55
  • 2
    Can you add the code portion of your component that contains myvar variable initialization? ContractNumber is a class, not exactly sure how you managed to do myvar.ContractNumber.... Would of made sense if it was myvar.GetCompanyContractNumber() when you new up the ContractNumber object. Commented Apr 10, 2017 at 16:04
  • @bakerhumadi is not working.. Commented Apr 10, 2017 at 16:09
  • @12seconds I have a class: export class Contract { ... public ContractNumber:ContractNumber; ... } and i have a api which returns me a list of Contracts so in my template i am doing this: <div class="col-md-12" *ngFor="let cashingContract of cashingContracts"> <label>{{cashingContract.ContractNumber.GetCompanyContractNumber()}}</label> </div> Commented Apr 10, 2017 at 16:13
  • @Sparky, did you check if either cashingContracts has objects in it? and that your property ContractNumber is not null. Commented Apr 10, 2017 at 16:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.