2015-11-12 44 views
0

我有這樣的事情,和它的工作如預期:爲什麼我把它放在那裏

$document.on('click', this.clickHandler.bind(this)); 

沒有bind(this),裏面clickHandler事件的this將指向文檔對象,這樣的。但是,當我嘗試解除綁定時,它的行爲不正確。我曾嘗試過以下幾種:

$document.off('click', this.clickHandler); 

$document.off('click', this.clickHandler.bind(this)); 

$document.unbind('click', this.clickHandler); 

沒有一個能像我所期望的那樣工作。我想從$ document中刪除特定的單擊事件處理程序(連同其this上下文)。例如,我想在$scope.$destroy中這樣做。

回答

0

我得到它的工作:

$document.off('click', this.clickHandler).unbind();