Vishal Kamal Vishal Kamal - 1 year ago 78
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.

Answer Source

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; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download