0

I have created recursive (rec) function inside setBinary method in typescript. But some reason it is not working in typescript but working in Angular.

How to convert the following angular to typescript.

While running gives an error "rec is not a function"

setBinary(rowId, vId, data) {          
   let pri;
    let pvi;
    let rec;


    rec (pri, pvi) {
        let latest = [];
        if (this.copyColumns[pri]) {
            this.copyColumns[pri].values[pvi].active = true;          

           let  x = this.copyColumns[pri].values[pvi]
            rec(x.pri, x.pvi)
        }
    };

    rec(data.pri, data.pvi)

}
1
  • rec must be declared a function, if this code is to run in either typescript or javascript Commented Mar 10, 2019 at 4:56

1 Answer 1

1

Once you declare your function setBinary and your function rec, you have code which will compile.

function setBinary(rowId, vId, data) {          
    let pri;
    let pvi;

    let rec = function (pri, pvi) {
        let latest = [];
        if (this.copyColumns[pri]) {
            this.copyColumns[pri].values[pvi].active = true;          

           let  x = this.copyColumns[pri].values[pvi]
           rec(x.pri, x.pvi)
        }
    };

    rec(data.pri, data.pvi)
}
Sign up to request clarification or add additional context in comments.

Comments

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.