简体   繁体   English

如何改善 eslint-plugin-angular 观看错误?

[英]How to improve eslint-plugin-angular on-watch error?

$rootScope.$on('$stateChangeStart', function (event, state) {
            ...
        })

result -> es lint error The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event结果 -> es lint 错误“$on”调用应该分配给一个变量,以便在 $destroy 事件期间被销毁

but if i correct it like in the documentation但如果我像在文档中一样纠正它

var unregister = $rootScope.$on('$stateChangeStart', function (event, state) {
            ...
        })

i get "unregister is defined but never used" error我收到“取消注册已定义但从未使用过”错误

What is the best way to correct this issue?解决此问题的最佳方法是什么?

The unregister variable that is returned by $rootScope.$on is a function that needs to be called to unregister the watch. $rootScope.$on返回的unregister变量是一个需要调用以取消注册 watch 的函数。 A common use case is to call it when the current scope is destroyed:一个常见的用例是在当前作用域被销毁时调用它:

$scope.$on('$destroy', unregister);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM