2016-10-15 36 views
3

我無法綁定全局變量。在angularjs中使用addListener進行雙向綁定2

在這裏我的代碼。

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

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

顯示「true」,但它不反映在html上。

請幫幫我。

+0

請提供更多的上下文。在Angular2中你有這個代碼嗎? 「mxUtils」在什麼地方? –

+0

mxUtils是mxgraph類 –

+0

@GünterZöchbauer 我想這也: mxEvent.addListener(IMG, '點擊',功能(事件:任意){ this.enableRightSideBar = TRUE; }) 不是爲我工作。 –

回答

2

沒有在你的問題太多信息,但我想這是你需要做什麼:

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

更新

看來這個回調角度帶外線發炮,所以你可以使用ChangeDetectorRef刷新視圖:

constructor(private cdRef: ChangeDetectorRef) {} 

... 
this.enableRightSideBar = true; 
this.cdRef.detectChanges(); 
+0

我已經試過這個 –

+0

當我嘗試更改 this.enableRightSideBar = true; 使用按鈕事件。它的工作正常,但它不適用於addListener。 –

+0

您是否考慮過提供以上2倍以上的更多信息? –

相關問題