Vishal Kamal Vishal Kamal - 7 months ago 28
TypeScript Question

two way binding with addListener in angularjs 2

I'm not able to bind global variable.

here my code.

mxEvent.addListener(img, 'click',
mxUtils.bind(this, function(evt:any) {
this.enableRightSideBar = true;

console.log(this.enableRightSideBar, 'this.enableRightSideBar');

Show me "true", but it's not reflected on html.

Please help me.


There isn't much information in your question but I guess this is what you need to do:

mxEvent.addListener(img, 'click', (event:any) => { this.enableRightSideBar = true; })


Seems this callback is fired outside angular zone so you can use ChangeDetectorRef to refresh view:

constructor(private cdRef: ChangeDetectorRef) {}

this.enableRightSideBar = true;