0

I am attempting to change the variable "currSideNavId" inside the jQuery on() method using Angular6. The current code below gives me TS error:

[ts] Cannot find name 'currSideNavId'. [2304]

I am not sure how I can go about changing the global variable in this jQuery method. Thank you.

export class TimelineCreatorComponent implements OnInit {
    currSideNavId: number;

    ngOnInit (){
       this.timeline.on('select', function (properties) {
         console.log('selected items: ' + properties.items);
         currSideNavId = properties.items;

       });
    }
}
bwiz
  • 407
  • 5
  • 13
  • You can define the callback as an arrow function: `(properties) => { this.currSideNavId = properties.items; }`. – ConnorsFan Dec 11 '18 at 02:56

1 Answers1

1

Here is the one way of doing.

export class TimelineCreatorComponent implements OnInit {
    currSideNavId: number;
    let me = this;
    ngOnInit (){
       this.timeline.on('select', function (properties) {
         console.log('selected items: ' + properties.items);
         me.currSideNavId = properties.items;

       });
    }
}
Suresh Kumar Ariya
  • 9,516
  • 1
  • 18
  • 27